温馨提示×

python整型转字符串怎么实现

小亿
92
2023-12-05 09:38:54
栏目: 编程语言

要将整型转换为字符串,可以使用内置函数str()。例如:

num = 123
str_num = str(num)
print(type(str_num))  # 输出<class 'str'>

另一种方法是使用字符串的格式化方法,将整型插入到字符串中。例如:

num = 123
str_num = "{}".format(num)
print(type(str_num))  # 输出<class 'str'>

上述两种方法都可以将整型转换为字符串。

0