Python Tuple Data Type (PYTHON FUNDAMENTALS)

Created with Sketch.

Python Tuple Data Type

  •  tuple data type is exactly the same as the list data type except that it is immutable. i.e we
    cannot change values.
  •  Tuple elements can be represented within parentheses.

Eg:

 t=(10,20,30,40) 
 type(t) 
 <class 'tuple'> 
 t[0]=100 
 TypeError: 'tuple' object does not support item assignment 
 >>> t.append("durga") 
 AttributeError: 'tuple' object has no attribute 'append' 
 >>> t.remove(10) 
 AttributeError: 'tuple' object has no attribute 'remove'

Note: tuple is the read-only version of the list.

Leave a Reply

Your email address will not be published. Required fields are marked *