Search This Blog

Tuple Concept in Python:-

A tuple is a collection of finite elements which can not be modified dynamically means tuple provide an immutable object, It is basically used to create constant LIST.


Tuple will be declared by ()  small bracket but accessed by []


x = ("C","C++",1200,1200)

means we can not change the value of x  anyways.

x[0]= 12  #error we can not change tuple elements

x.append() #tuple can not be append


Where we use tuple in the project?

In the project, if we want to declare a set of constant then we can use a tuple object because the tuple object can not be modified hence it is also called an immutable object in python.



Tuple Example:-

s = ("C","CPP",1200,3500,12.34)
#s[0]=12
#del s[0]
#s.append(12)
for i in range(0,len(s)):
    print(s[i])



Tuple using for each Loop:-

x= (12,23,34,56,67)
for x1 in x:
    print(x1)

Tuple basic operation:-

We can add, repeat, and delete tuple objects.


a=(1,2,3)
b=(4,5,6)
c=()
c=a+b
c

........................................................................................................................................................

a= (1,2,3)*4
print(a)

......................................................................................................................................................




Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post