List and Tuple
Title
Question
The basic difference between list and tuple
Python-3.4.3 Getting-started-with-Lists 05-06 min 10-20 sec
Answers:
The list is an Data structure similar to an array. It is mutable, meaning that the same list object can be changed.
Tuple on the other hand is a immutable data structure and cannot be changed, hence one has to create a new tuple in case of changes
The key difference is that tuples are immutable. This means that you cannot change the values in a tuple once you have created it. This is a good feature to have in some data structures where you intend to not make any changes to certain parts. As a list is mutable, it can't be used as a key in a dictionary because dictionaries can use any immutable object as a key. Thus, tuples can be used as dictionary keys if needed. If you try to modify a tuple in a permitted way it becomes two Tuples: the original, which remains fo every scope other than yours, and your modified copy for your scope.
http://net-informations.com/python/iq/immutable.htm
Login to add comment