Python 改变字符串变量的值

3

我是Python的新手,我想知道如何改变一个已经设置好的字符串变量。

例如:

name ='school'

如果我想要使用像 GeorgeBenJessKatie 等不同的值来替换变量名,我该如何更改呢?


就像其他编程语言一样,只需将名称变量分配给新的字符串值即可。 - mario
1个回答

2
您可以像最初分配值给变量一样使用赋值运算符=来为变量分配新值。
name = 'school'
print 'the current value of name is:', name
name = 'George'
print 'the current value of name is:', name

结果:

the current value of name is: school
the current value of name is: George

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接