list() 的属性是如何Case 1
调用的,它使输出与print y
不同Case 2
?
# Case 1: using a list as value
>>> x = ["one", "two", "three"]
>>> y = x
>>> x[0] = "four"
>>> print x
["four", "two", "three"]
>>> print y
["four", "two", "three"]
# Case 2: using an integer as value
>>> x = 3
>>> y = x
>>> x = x + 1
>>> print x
4
>>> print y
3
编辑:
为了表明这种行为与列表是可变的和字符串无关,而不是案例 2,可以给出以下案例:
>>> x = ["one", "two", "three"]
>>> y = x
>>> x = x + ["four", "five"]
>>> print x
["four", "two", "three", "four", "five"]
>>> print y
["four", "two", "three"]