如何将整数转换为字符串?
42 ⟶ "42"
For the reverse, see How do I parse a string to a float or int? https://stackoverflow.com/questions/379906/. Floats can be handled similarly, but handling the decimal points can be tricky because floating-point values are not precise https://stackoverflow.com/questions/588004/. See Converting a float to a string without rounding it https://stackoverflow.com/questions/1317558 for more specific advice.
>>> str(42)
'42'
>>> int('42')
42
文档链接:
- int() https://docs.python.org/3/library/functions.html#int
- str() https://docs.python.org/3/library/functions.html#func-str
str(x)
转换任何对象x
通过调用转换为字符串x.__str__() https://docs.python.org/3/reference/datamodel.html#object.__str__
, or repr(x) https://docs.python.org/3/library/functions.html#repr if x
没有__str__()
method.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)