Sunday, 5 June 2016

python - Converting integer to string?



I want to convert an integer to a string in Python. I am typecasting it in vain:




d = 15
d.str()


When I try to convert it to string, it's showing an error like int doesn't have any attribute called str.


Answer



>>> str(10)
'10'
>>> int('10')
10



Links to the documentation:





Conversion to a string is done with the builtin str() function, which basically calls the __str__() method of its parameter.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...