0

How to convert integer to string?

I know only one method in python to convert integer to string n = 10 m = str(n) print(type(m)) Are there any other methods?

5th Jan 2022, 6:14 PM
Harsha S
Harsha S - avatar
5 Answers
+ 4
# how about string formating? x = f"{42}" print(type(x)) x = "{0}".format(42) print(type(x)) # edit: x = repr(42) print(type(x)) x = (42).__str__() print(type(x))
5th Jan 2022, 6:18 PM
Lisa
Lisa - avatar
+ 5
For digits conv=dict(enumerate("0123456789"))
5th Jan 2022, 6:50 PM
Oma Falk
Oma Falk - avatar
+ 4
convert=dict(zip[0,1,2,3,4,5,6,7,8,9],"0123456789")) n=432 word="" while n > 0: n,r=divmod(n,10) word=convert[r]+word
5th Jan 2022, 6:43 PM
Oma Falk
Oma Falk - avatar
+ 1
Lisa what's repr?
6th Jan 2022, 3:06 AM
Harsha S
Harsha S - avatar
+ 1
"Return a string containing a printable representation of an object." https://docs.python.org/3/library/functions.html#repr
6th Jan 2022, 7:54 AM
Lisa
Lisa - avatar