MENU
Question -

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)

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×