>>> aTuple = (123, 'string', 333.0, [1,2,3]) >>> aTuple (123, 'string', 333.0, [1, 2, 3]) >>> t = tuple('test') >>> t ('t', 'e', 's', 't') >>>
>>> aTupe (1, 'two', ['lucky', 'happy'], 3.3) >>> aTupe[1:3] ('two', ['lucky', 'happy']) >>> aTupe[1:] ('two', ['lucky', 'happy'], 3.3) >>> aTupe[2][1] 'happy' >>>
>>> aTupe = aTupe[0], aTupe[1] >>> aTupe (1, 'two')
>>> hubby = person[:] >>> wifey = list(person) >>> [id(x) for x in person, hubby, wifey] [140032524226712, 140032524226784, 140032524227144] >>> hubby[0] = 'joe' >>> wifey[0] = 'jane' >>> hubby, wifey (['joe', ['saving', 100.0]], ['jane', ['saving', 100.0]]) >>> hubby[1][1] = 50.00 >>> hubby, wifey (['joe', ['saving', 50.0]], ['jane', ['saving', 50.0]]) >>> [id(x) for x in hubby] [140032524156760, 140032524144512] >>> [id(x) for x in wifey] [140032524223856, 140032524144512] >>>当hubby的账号余额变成50,wifey的账号余额也变成50了。但为什么两个账户的名字又不相同呢?
>>> person = ['name', ['saving', 100.00]] >>> hubby = person >>> import copy >>> wifey = copy.deepcopy(person) >>> [id(x) for x in person, hubby, wifey] [140032524227072, 140032524227072, 140032524227216] >>> hubby[0] = 'joe' >>> wifey[0] = 'jane' >>> hubby, wifey (['joe', ['saving', 100.0]], ['jane', ['saving', 100.0]]) >>> hubby[1][1] = 50.00 >>> hubby, wifey (['joe', ['saving', 50.0]], ['jane', ['saving', 100.0]]) >>> [id(x) for x in hubby] [140032524231544, 140032524226856] >>> [id(x) for x in wifey] [140032524224096, 140032524227360] >>>
原文地址:http://blog.csdn.net/u012088213/article/details/44891201