What is the difference between a python list and a tuple?

PythonServer Side ProgrammingProgramming

The key difference between a list and a tuple is that tuples are immutable. This means that you cannot change the values in a tuple once you have created it. So if you're going to need to change the values use a List.

Benefits of using tuples −

  • They help in slight performance improvement.

  • As a tuple is immutable it can be used as a key in a dictionary.

  • If you can't change it neither can anyone else, which is to say you don't need to worry about any API functions etc. changing your tuple without being asked.

  • They take up less space than lists.

You can read more about the differences between lists and tuples in Python here − http://news.e-scribe.com/397

Published on 05-Jan-2018 12:37:29