Saved Bookmarks
| 1. |
What is the difference between list and tuple ? Give an example. |
|
Answer» Lists are Python’s general purpose container, often used for collections of similar objects. Lists are mutable objects that can contain any Python data. Example : >my list = [ ] # make an Empty list >my list = [1,1.0+3j, “aperitivo”, true] # make a list containing four entities. A Tuple is an immutable value (can’t be changed) that can contain any Python data. They are generally used for small collectioin of data. Example : >mytuple = [1, 2, 3, 4) # create a four element tuple. >mytuple[2] = 4 # Error – tuple can’t be modified. > print mytuple[2], len(mytuple) |
|