Python
tuple datatype:
- Major difference between tuple and dictionary is, - Tuple is immutuable while Dictionary in python is mutuable.
- Once element is inside a tuple, it can not be reassigned.
- Tuple uses round paranthesis. Example,- (1, 2, 3)
Tuple operations
Input =>
my_tuple = ('One', 'Two', 'Three', 'Four', 'Five', 'Six')
my_tuple[2]
my_tuple[-1]
Output =>
Three
Six
Methods:
Input =>
my_tuple = ('One', 'Two', 'One', 'Four', 'Five', 'One')
Method | Usage | Output | Additional Information |
---|---|---|---|
count() | my_tuple.count(‘One’) | 3 | Method use to count occurances of given parameter |
index() | my_tuple.index(‘Four’) | 3 | Method use to return first index of given parameter |
python-documentation is maintained by ravaan-techky.