Python- Tuples

                       Basic Orations on Tuples in Python


##tuple and list are same but only one main diffrence in tuple and list is we can update list values but we cant update or chang tuple values
#we create list using "list=[]"

tuple1=("rohan","anil","gaikwad",1,2,3)
print(tuple1)


#############empty tupple#########

tuplee=()
print(tuplee)

#################index Values################

print (tuple1[2])
print (tuple1[0:2])  ####includeing 0 index value and excluding 2 index value
print (tuple1[1:])

#####################
#tuple1[0]="vivk"
#print(tuple1)
#del tuplee       ####tupple does not suport update and delete opration 
#print (tuplee)

###############length of string#########

print(len(tuple1))

#########concatnate#############

tuple2=(1,2,3,4,5,6,7)
tuple3=tuple1+tuple2
print (tuple3)
print (tuple1 * 2) #making copy of tuple
print (tuple1 * 9) #making copy of tuple

################Search value in tuplle ,if present writeen true otherwise false

print(5 in tuple3)
print(max(tuple2))
print(min(tuple2))

##################################list in tuple################
list1=[7,8,9,10]
print(tuple(list1))  #if we print only list it shows [7,8,9,10] and if we print list in tuple it gives output (7,8,9,10)

#Go line by line u will understand below output
############################OUTPUT##################################

('rohan', 'anil', 'gaikwad', 1, 2, 3)
()
gaikwad
('rohan', 'anil')
('anil', 'gaikwad', 1, 2, 3)
6
('rohan', 'anil', 'gaikwad', 1, 2, 3, 1, 2, 3, 4, 5, 6, 7)
('rohan', 'anil', 'gaikwad', 1, 2, 3, 'rohan', 'anil', 'gaikwad', 1, 2, 3)
('rohan', 'anil', 'gaikwad', 1, 2, 3, 'rohan', 'anil', 'gaikwad', 1, 2, 3, 'rohan', 'anil', 'gaikwad', 1, 2, 3)
True
7
1
(7, 8, 9, 10)

Comments