-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathexamples.py
More file actions
84 lines (55 loc) · 1.29 KB
/
examples.py
File metadata and controls
84 lines (55 loc) · 1.29 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
languages = []
languages.append("Java")
languages.append("Python")
languages.append("C#")
languages.append("Ruby")
print(languages)
numbers = [1, 2, 3]
imdb_top_3 = [
"The Shawshank Redemption",
"The Godfather",
"The Godfather: Part II"
]
print(imdb_top_3)
empty = []
mixed = [1, True, "Three", [], None]
print(mixed)
# len is a "built-in" function
# more on them, here - https://docs.python.org/3/library/functions.html
if len(empty) == 0:
print("Empty list check with len")
# bool([]) == False
# bool([1]) == True
if numbers:
print("Numbers is non-empty")
if not empty:
print("empty is empty")
# How to check if a given value exists in a list
if 1 in numbers:
print("1 is in numbers")
if 10 not in numbers:
print("10 is not in numbers")
for n in numbers:
print(n)
for movie in imdb_top_3:
print(movie)
for nothing in empty:
print(nothing)
for item in mixed:
print(item)
# Lists have standard index access
print(numbers[0])
# Lists can be mutated
print(numbers)
numbers[0] = 111
print(numbers)
print(empty)
empty.append("Something")
print(empty)
# We can easily compare lists
# Two lists xs & ns are equal, if
# xs[i] == ns[i] for every index i of that lists
# or if both xs & ns are empty
print([] == [])
print([1] == [])
print([1, 2] == [2, 1])