-1

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.

0

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

Comments

0

foo = (1,2,3) gives you a tuple; foo = [1,2,3] gives you a list. maybe start here?

1 Comment

Thank you for the info.. I will start with that...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.