温馨提示×

Python数字怎么转换为字符串

小亿
97
2024-03-18 16:21:47
栏目: 编程语言

要将一个Python数字转换为字符串,可以使用内置的str()函数。示例如下:

num = 123
str_num = str(num)
print(str_num)  # 输出:'123'

另外,也可以使用字符串的format()方法来将数字插入到字符串中,例如:

num = 123
str_num = "The number is {}".format(num)
print(str_num)  # 输出:'The number is 123'

0