-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuple.py
51 lines (27 loc) · 1.22 KB
/
tuple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
''' TUPLE
A tuple is a collection which is ordered and unchangeable(immutable).
'''
''' Adding Elements '''
print("**********Adding Elements**********", end="\n\n")
tuple = (1, 2, 3, 'Alphabet')
print(f"Tuple is {tuple}", end="\n\n")
''' Accessing Elements '''
print("**********Accessing Elements**********", end="\n\n")
for x in tuple:
print(f"Element of tuple is {x}")
print(f"\nGetting whole Tuple {tuple}", end="\n\n")
print(f"0th Elements of Tuple is {tuple[0]}", end="\n\n")
print(f"Can be accessed through ':' Operator {tuple[:]}", end="\n\n")
print(f"Reversed Tuple is {tuple[::-1]}", end="\n\n")
print(f"Letter-at-3-index of 3rd-Index-elements is {tuple[3][3]}", end="\n\n")
''' Appending Elements '''
print("**********Appending Elements**********", end="\n\n")
tuple = tuple + (4, 5, ['B', 'C']) #add elements
print(f"Tuple after appending elements is {tuple}", end="\n\n")
# (1, 2, 3, 'Alphabet', 4, 5, ['B','C'])
''' Other Functions '''
print("**********Other Functions**********", end="\n\n")
tuple[6][0] = 'K'
print(f"Changed 6th-index-element to K {tuple}", end="\n\n")
print(f"2 has been repeated {tuple.count(2)} time", end="\n\n")
print(f"Index of ['K','C'] is {tuple.index(['K', 'C'])}", end="\n\n")