繁体   English   中英

如何将 integer 更改为 python 中的字符串?

[英]how do you change an integer to a string in python?

我正在尝试编写游戏代码,但它不断弹出can only concatenate str (not "int") to str我试过print('sample text' + variable + 'sample text')

您可以转换为str或使用 f 字符串(格式字符串)。

print('sample text' + str(variable) + 'sample text')

或者

print(f'sample text {variable} sample text')

尝试使用print(str(variable))用字符串包装它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM