forked from shubhansu-kr/INT213-Python-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13_Tuples.py
42 lines (31 loc) · 846 Bytes
/
13_Tuples.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
# Tuples
tuple1 = ()
print(tuple1)
# Homogeneous data : List
# Hetrogeneous data : tuple
tuple2 = (1, 2, 5, 7, 8, 8, 'sh', 'dsk')
print (tuple2)
# Tuples are immutable/unmodifiable, whereas list are mutable/modifiable
# We can create tuples without parenthesis : Tuple packing
tuple4 = 1,4
print (tuple4)
# Tuples identification
tuplesa = ('Shubh')
tuplesd = 'shubh'
tuplesc = ('Shubh', )
tuplesb = 'Shubh' ,
# Destructuring of tuples
a, b = tuple4
print(a)
print(b)
tuple11 = (3, 4, 3, [4,3])
print (tuple11[2]) #Prints 3
# Let's try to update any value
# tuple11[2] = 2 -----> Error: cannot modify the tuple
# print (tuple11)
# Only modification allowed in tuple is concatination
tuple11 += tuple2
print (tuple11)
# Lets try to modify list within tuple : Yes it is possible
tuple11[3][1] = 101 # Noerror
print (tuple11)