How to convert int to string in PythonWe can convert an integer data type using the Python built-in str() function. This function takes any data type as an argument and converts it into a string. But we can also do it using the “%s” literal and using the .format() function. Below is the syntax of the str() function. Syntax – Let’s understand the following example. Example – 1 Using the str() function Output: <class 'int'> 25 <class 'str'> 25 Example – 2 Using the “%s” integer Output: <class 'int'> <class 'str'> Example – 3: Using the .format() function Output: <class 'int'> <class 'str'> Example – 4: Using f-string Output: <class 'int'> <class 'str'> We have defined all methods of converting the integer data type to the string type. You can use one of them according to your requirement. |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263626.html