小编Joh*_*Hon的帖子

为什么字符串变量更改时不更新

假设我们有一些像这样的代码:

placehold = "6"
string1 = "this is string one and %s" % placehold

print string1

placehold = "7"
print string1
Run Code Online (Sandbox Code Playgroud)

运行时,两个 print 语句都返回,就好像 placehold 始终为 6。但是,就在第二条语句运行之前,placehold 更改为 7,那么为什么它没有动态反映在字符串中呢?

另外,您能建议一种使字符串返回 7 的方法吗?

谢谢

python string string-formatting python-2.7

3
推荐指数
1
解决办法
3523
查看次数

标签 统计

python ×1

python-2.7 ×1

string ×1

string-formatting ×1