且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Python中用字符串和整数创建一个字符串

更新时间:2022-11-17 10:51:18

name = 'b' + str(num)

name = 'b%s' % num

如S.Lott所说,对于Python 3及以上版本,不推荐使用混合运算符'%'。我从 INTERCAL 中偷走了mingle这个名字,但这就是我谈论它的方式。我想在之前至少看过一次 - 比如渡渡鸟 - 它从地球上消失了。

as S.Lott notes, the mingle operator '%' is deprecated for Python 3 and up. And I stole the name "mingle" from INTERCAL but that's how I talk about it and wanted to see it in print at least once before - like the dodo - it vanishes from the face of the earth.