tuple in python

Previous
Next

tuple

  • It is an ordered collection.
  • It allow to store duplicates.
  • It can stores different type of elements.
  • We can represent the tuple with ( )
>>> t = (10,20,30,40,50)
>>> print(t)
(10, 20, 30, 40, 50)
>>> t = (10,20,10,23.45,"abc")
>>> print(t)
(10, 20, 10, 23.45, 'abc')

We can process elements using indexing and slicing

>>> len(t)
5
>>> t[0]
10
>>> t[-1]
'abc'
>>> t[2:5]
(10, 23.45, 'abc')
Previous
Next

Add Comment

Courses Enquiry Form