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?
5 ответов
+ 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))
+ 5
For digits
conv=dict(enumerate("0123456789"))
+ 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
+ 1
Lisa what's repr?
+ 1
"Return a string containing a printable representation of an object."
https://docs.python.org/3/library/functions.html#repr