int to str in python

To convert an integer to a string in Python, you can use the str() function. Here's an example:

main.py
num = 42
str_num = str(num)
print(type(str_num)) # <class 'str'>
65 chars
4 lines

In the example above, we first define a variable num and set it to an integer value of 42. We then use the str() function to convert this integer to a string, and store the result in a new variable called str_num. We can then verify that the type of str_num is indeed a string using the type() function. The output of this program should be <class 'str'>.

related categories

gistlibby LogSnag