What is the defference between foo = (1,2,3) and foo = [1,2,3] in python Can any body explain me the difference between them more clearly.
Asked
Active
Viewed 166 times
2 Answers
1
The first is a tuple which is an immutable type.
>>> foo = (1,2,3)
>>> foo[0] = 42
Traceback (most recent call last): File "", line 1, in TypeError: 'tuple' object does not support item assignment
The second is a list, which is mutable.
>>> foo = [1,2,3]
>>> foo[0] = 42
>>> foo
[42, 2, 3]
There are other very important differences between lists and tuples. Please see this question and its answers:

Community
- 1
- 1

Mark Byers
- 811,555
- 193
- 1,581
- 1,452
0
foo = (1,2,3) gives you a tuple; foo = [1,2,3] gives you a list. maybe start here?

Alexander Corwin
- 1,097
- 6
- 11
-
Thank you for the info.. I will start with that... – Ranjitha Mar 23 '12 at 21:25