Monday, July 15, 2019

Tuple concepts

Script

#!/usr/local/bin/python3.4

tuple = ( 'ABCD', 221, 4752.23, 'Chandra', 77.7  )
smalltuple = (18000, 'Vishy')

print(tuple)                                                    # Prints the complete list
print(tuple[0])                                                 # Prints the first element of the list
print(tuple[1:3])                                               # Prints the elements starting from 2nd till 3rd
print(tuple[2:])                                                # Prints the elements starting from 3rd element
print(smalltuple * 3)                                            # Prints the list three times
print(tuple + smalltuple)                                        # Prints the concatenated lists


Execution

('ABCD', 221, 4752.23, 'Chandra', 77.7)
ABCD
(221, 4752.23)
(4752.23, 'Chandra', 77.7)
(18000, 'Vishy', 18000, 'Vishy', 18000, 'Vishy')
('ABCD', 221, 4752.23, 'Chandra', 77.7, 18000, 'Vishy')



No comments:

Post a Comment