-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTupleDataType.py
More file actions
80 lines (60 loc) · 1.14 KB
/
Copy pathTupleDataType.py
File metadata and controls
80 lines (60 loc) · 1.14 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
newList = (1, 2, 3, "maria", True, 'm')
print(type(newList))
print(newList[2])
# neg index
print(newList[-3])
# range of index
print(newList[3:6])
print('')
# update tuple
tuple1 = ("m", "r", "i")
print(tuple1)
a = list(tuple1)
a.append("a")
a.insert(1, "a")
tuple1 = tuple(a)
print(tuple1)
print('')
# unpack tuple
tuple2 = ("apple", "banana", "cherry", "dog", "elephant")
(a, b, c, d, e) = tuple2
print(d)
# asterisk using
(a1, *a3, a2) = tuple2
print(a3)
print('')
# loop tuple
tuple3 = [10, 20, 30, 40, 50]
# for loop
for x in tuple3:
print(x)
# using range & len
print("Index Number:")
for y in range(len(tuple3)):
print(y)
print("Value:")
for z in range(len(tuple3)):
print(tuple3[z])
# while loop
tuple4 = ['a', 's', 'd', 'f', 'g']
print("While loop:")
i = 0
while i < len(tuple4):
print(tuple4[i])
i += 1
print('')
# join tuple
t1 = [1, 2, 3, 4, 5]
t2 = [6, 7, 8, 9, 10]
t3 = t1 + t2
print(t3)
# multiply tuple
t4 = t1*2
print(t4)
print('')
# method tuple
mt = [1, 2, 2, 2, 5, 6, 9, 87, 3, 5, 6, 4]
ind = mt.index(5) # index method
print("Index of 5:", ind)
cnt = mt.count(2) # count method
print("Counting 2:", cnt)