-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlists_tuples_sets.py
More file actions
47 lines (32 loc) · 1.28 KB
/
lists_tuples_sets.py
File metadata and controls
47 lines (32 loc) · 1.28 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
# Example of list with For loop:
x = [1, 2, 3, 4, 5, 6, 7, 8]
y = x[:]
print("This prints the last indexed value of the 'x' list:")
print(x.pop(), x)
print("This prints the value of the 'y' list, which is the 'x' list prior to being 'popped':")
print(y)
print("This prints the values within the 'x' list alongside each values' index:")
for num, element in enumerate(x):
print(num, element)
print("____________________________________________________________________")
# Example with While loop:
i = 1
while True:
print("This is an example of a while loop, which has run", i, "out of 10 times")
i += 1
if i == 11:
break
print("____________________________________________________________________")
# Example of Slice operator:
slicer = x[0:6:2]
print("This prints from one value to another within a list or range, stepping a specified number between each:")
print(slicer)
print("____________________________________________________________________")
# Examples of Sets:
s1 = {1, 2, 3, 55, 4, 4, 0}
s2 = {"a", "b", "c", "d", 9, "x", "y"}
print("This prints the contents of set 's1':")
print(s1)
print("...and this prints the contents of 's1' after being combined with '2':")
print(s1.union(s2))
print("____________________________________________________________________")