-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_tuples.py
More file actions
50 lines (36 loc) · 1.14 KB
/
Copy path06_tuples.py
File metadata and controls
50 lines (36 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
### Tuples ###
my_tuple = tuple()
my_other_tuple = ()
my_tuple = (22, 1.89, 'Mike', 'Treyu', 'Mike')
my_other_tuple = (35, 60, 30)
print(my_tuple)
print(type(my_tuple))
print(my_tuple[0])
print(my_tuple[-1])
#print(my_tuple[4]) indexError
#print(my_tuple[-6]) indexError
print(my_tuple.count('Mike'))
print(my_tuple.index('Mike'))
'''
my_tuple[1] = 1.80
print(my_tuple)
you can't change the values of a tuple, nor add new information, no modification. it doesn't support item assignment
'''
print(my_tuple + my_other_tuple)
my_sum_tuple = my_tuple + my_other_tuple
print(my_sum_tuple)
print(my_sum_tuple[3:6])
'''
we can't change the values of a tuple, but we can convert a tuple in a list so we can change the values inside.
'''
my_tuple = list(my_tuple)
print(type(my_tuple))
my_tuple[4] = 'Miketreyu'
my_tuple.insert(1, 'Red')
my_tuple = tuple(my_tuple)
print(my_tuple)
print(tuple(my_tuple))
#del my_tuple[2] TypeError: 'tuple' object doesn't support item deletion
del my_tuple
#print(my_tuple) NameError: name 'my_tuple' is not defined.
#the tuple has been deleted (this is strange because if you can't change tuples, you should't be able to delete)