PDA

View Full Version : is it Tuple's method ?



mocqueanh
July 30th, 2007, 04:09 AM
x = ([0,1], 2)
x[0][1] = 'Python'

I've cheat Python, right ?:confused:

Jessehk
July 30th, 2007, 04:13 AM
x = ([0,1], 2)
x[0][1] = 'Python'

I've cheat Python, right ?:confused:

As far as I understand it the structure of the tuple itself is constant, not the objects contained within it.

pmasiar
July 30th, 2007, 05:12 AM
x = ([0,1], 2)
x[0][1] = 'Python'


try type(x[0]): x[0] is a list. You would be surprised if you could not change a list? If you do instead:

z = ((0,1), 2)

you see you cannot assign to the tuple:

z[0][1] = 's' # this fails: TypeError: 'tuple' object does not support item assignment