-
Notifications
You must be signed in to change notification settings - Fork 17
/
Tuples.py
51 lines (42 loc) · 1.13 KB
/
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
43
44
45
46
47
48
49
50
51
print(
"Tuples in Python are ordered collection of elements. They are immutable."
+ "They can have Strings, numbers, Float, and more or a combination of all of them"
)
print()
print("For tuples in python, we use round brackets")
a = ("One", 2, "Three", "Four", 5)
print("Tuple a: ", a)
print()
print("Use comma to create a tuple with only one item")
b = ("Only",)
print("Tuple b: ", b)
print()
print("Each element has an unique index starting from 0, similar to a list.")
print("First element in a: ", a[0])
print()
print("Return value of a new tuple can be specified by a range.")
print("Index 2 to 5 in a: ", a[2:4])
print()
print(
"To change values in a tuple, convert the tuple into a list and make some changes."
)
c = ("red", "orange", "blue")
d = list(c)
d[1] = "yellow"
c = tuple(d)
print("Change second element in c: ", c)
print()
print("To delete tuple, use del.")
e = (2, 4, 6)
del e
print()
print("To join tuples, use + operator")
f = ("plus", "minus")
g = (10, 100)
h = f + g
print("Joined tuple is: ", h)
print()
print("Tuple c is: ", c)
print("Length of tuple c: ", len(c))
print()
input("Press Enter key to exit ")