forked from jmbharathram/executeoncommand
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6_tuples.py
More file actions
43 lines (23 loc) · 682 Bytes
/
6_tuples.py
File metadata and controls
43 lines (23 loc) · 682 Bytes
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
Tuple is an ordered collection of objects, that is immutable.
list_1 = ['Banana', 'Apple', 'Water Melon', 'Pineapple', 'Mango'] #List
tuple_1 = ('Banana', 'Apple', 'Water Melon', 'Pineapple', 'Mango') #Tuple
set_1 = { "v1", "v2", "v3"} #set
#unordered vs ordered data structure
print(set_1)
print(tuple_1)
#immutable
list_1[0] = "Kiwi"
tuple_1[0] = "Kiwi"
# List or a mutable object inside tuple
tuple_2 = ('Cherry', 'Kiwi', ['Strawberry'])
tuple_2[2].append('Blueberry')
# Packing and Unpacking
tuple_3 = ('Banana', 'Apple', 'Water Melon')
(fruit_1, fruit_2, fruit_3) = tuple_3
fruit_1, fruit_2, fruit_3 = tuple_3
# Swapping
a = 3
b = 4
a, b
b, a
a, b = b, a