在 Python 中将整数转换为字符串

在 Python 中将整数转换为字符串

问题描述:

我想在 Python 中将整数转换为字符串.我徒劳地排版它:

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

d = 15
d.str()

当我尝试将其转换为字符串时,它显示了一个错误,例如 int 没有任何名为 str 的属性.

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

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

文档链接:

转换为字符串是使用内置的 str() 函数完成的,该函数基本上调用了 __str__() 其参数的方法.

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