Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (47.6k points)

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 a string, it's showing an error like int doesn't have any attribute called str.

1 Answer

0 votes
by (106k points)
edited by

You can use the below-mentioned code to convert an integer to string:-

>>> str(10) 

'10' 

>>> int('10') 

10

Links to the documentation:

  • int()

  • str()

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

To know more about this you can have a look at the following video tutorial:-

 

 

Related questions

+3 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...