'''
This code use tuple syntax
tuple have no append,remove,index method
'''
mytuple=("i","am","the",1)
print mytuple
print mytuple[0]
print mytuple[-1]
print "tuple length ",len(mytuple)
'''
print tuple data
'''
for n in mytuple:
print n
print mytuple[0:2]
'''
compare two tuple
return 0 if two tuple are equal
'''
newtuple=mytuple
print cmp(mytuple,newtuple)
'''
get max data from a tuple
'''
integertuple=(1,2,6,3)
print max(integertuple)
'''
list array to tuple
'''
listArray=[]
listArray.append(2)
listArray.append(5)
listArray.append(3)
newtuple=tuple(listArray)
print newtuple
Output:
('i', 'am', 'the', 1)
i
1
tuple length 4
i
am
the
1
('i', 'am')
0
6
(2, 5, 3)

0 comments:
Post a Comment