-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_tuple.py
More file actions
27 lines (21 loc) · 725 Bytes
/
08_tuple.py
File metadata and controls
27 lines (21 loc) · 725 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
#Tuples
#Create tuple
fruit = ('Banana', 'Apple', 'Cherry', 'Strawberry', 'Pineapple')
#Print the ffirst item in the tuple:
print(fruit[0])
#Tuples are unchangeable, meaning that you cannot change, add, or remove items once the tuple is created.
#But there are some workarounds.
#But there is a workaround. You can convert the tuple into a list, change the list, and convert the list back into a tuple.
#Convert tuple into list
this_list = list(fruit)
#Update the element in first position to Kiwi
this_list[1] = 'Kiwi'
#Convert listo into tuple
fruit = tuple(this_list)
print(fruit)
#Join tuples
tuple_1 = ('Banana', 'Apple', 'Cherry')
tuple_2 = (1, 2, 3)
tuple_3 = tuple_1 + tuple_2
print(tuple_3)
print(len(tuple_3))