TUPLE:-

  • Tuple object can be created by using paranics ( ) are by calling tuple function are by assigning more than one value to a single variable.
  • Tuple is a immutable object.
  • Tuple support +ve and -ve index
Eg:-
        x=(10,20,30,40,50)
        print(x)
        print(type(x))
Output:
             (10, 20, 30, 40, 50)
             <class 'tuple'>
Eg2:-
         x=(10,20,30,40,50,60)
         print(x)
         print(type(x))
         print(x[2])
         print(x[0])
         print(x[-2])
         print(x[-1])
output:
             (10, 20, 30, 40, 50, 60)
             <class 'tuple'>
             30
             10
             50
             60
Eg3:-
          x=(10,20,30,40,50,60)
          print(x)
          print(20 in x)
          print(40 in x)
          print(80 in x)
Output:
             (10, 20, 30, 40, 50, 60)
             True
             True
             False
Eg4:-
         x=(100,12.12,3+4j)
         print(x)
         a,b,c=x
         print(a,type(a))
         print(b,type(b))
         print(c,type(c))
Output:
             100, 12.12, (3+4j))
             100 <class 'int'>
             12.12 <class 'float'>
             (3+4j) <class 'complex'>
Eg5:-
         x=(10,20,30,40,50,60,10)
         print(x)
         print(x.count(10))
         print(x.count(40))
         print(x.index(40))
         print(x.index(10))
Output:
             (10, 20, 30, 40, 50, 60, 10)
             2
             1
             3
             0