Professional Documents
Culture Documents
Python Programming 4
Python Programming 4
Python Programming 4
Sorting a char
>>> Company="TJ Idea for Innovation"
>>> 'z' in Company
Result:
False
>>> 't' in Company
Result:
True
Note: Its Case sensitive
>>> 'j' in Company
Result:
False
>>> 'TJ' in Company
Result:
True
>>> cart
['brush', 'chocolets', 'soap', 'soap', 'batteries',
'batteries']
To reverse the array variables index
>>> cart.reverse()
>>> cart
['batteries', 'batteries', 'soap', 'soap',
'chocolets', 'brush']
Exp16:Sort and Tuples
>>> mynumbers=[21,20,19,12,1,2,3]
>>> mynumbers
Result:
[21, 20, 19, 12, 1, 2, 3]
To sort the Integer values
>>> mynumbers.sort()
>>> mynumbers
Result:
[1, 2, 3, 12, 19, 20, 21]
To sort the string values
>>> sorted('TJ idea for innovation')
Result:
[' ', ' ', ' ', 'J', 'T', 'a', 'a', 'd', 'e', 'f', 'i', 'i', 'i', 'n', 'n',
'n', 'o', 'o', 'o', 'r', 't', 'v']
Note:Tuples are slightly similar to list which
exist with “( )” ,where tuples variable can’t be
inserted with new values or deleted.
>>> 22,3,6,9
Result:
(22, 3, 6, 9)
>>> TJ=(1,5,6,4,8)
>>> TJ
Result:
(1, 5, 6, 4, 8)
>>> TJ[3]
Result:
4