What's the difference between list and tuples?



What's the difference between list and tuples?..

Answer / Chandan Kumar

The main difference between lists and tuples is that lists are mutable, meaning you can change their contents, while tuples are immutable, meaning their contents cannot be changed. Here's an example:

```python
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)

my_list[0] = 'a'
print(my_list)
# Output: ['a', 2, 3]
my_tuple[0] = 'a'
# This will raise a TypeError: 'tuple' object does not support item assignment
```

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What is a CGI script in Python?

1 Answers  


What is the input function in python?

1 Answers  


where can I get the study material for python

1 Answers  


Give an example of shuffle() method?

1 Answers  


What is the Global Interpreter Lock (GIL) in Python?

1 Answers  


What is cgi in python?

1 Answers  


What type of a language is python? Interpreted or Compiled?

1 Answers  


How do you comment in python?

1 Answers  


What is the difference between python append () and extend () functions?

1 Answers  


Is it worth to learn python in 2019?

1 Answers  


What are its benefits of flask?

1 Answers  


Is using eval in python a bad practice?

1 Answers  


Categories