When Do You Use List Vs. Tuple Vs. Dictionary Vs. Set
The main difference between lists and tuples are, lists are mutable whereas tuples are not. You can always convert a tuple type object to a list type object.
>>> p = (1,2,3,4)>>> type(p)<type 'tuple'>>>> q=list(p)>>> type(q)<type 'list'>>>>
Dictionaries are hash table's (so to speak) in Python. Dictionary is a powerful object in python. Whenever you need to associate a key and value pair, it is advisable to use dictionary object.
List and Tuple are both ordered containers. If you want an ordered container of constant elements use tuple as tuples are immutable objects.
2009-2016 downloadmela.com. All rights reserved.