簡體   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