-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathcheatsheet.py
More file actions
54 lines (38 loc) · 789 Bytes
/
cheatsheet.py
File metadata and controls
54 lines (38 loc) · 789 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
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
# python cheat sheet
# Variable assignment (no type declaration)
x = 1
# array (called list in python)
arr = [1, 2, 3]
# dictionary
dictionary = {"key": "value", "other_thing": 2}
# Other types
t = True
f = False
s = "a string"
# for loop
for element in arr:
print(element) # 1 ... 2 ... 3
# tuple
a = ("test", 1)
# multiple assignment
x, y = a
# For loop through a dictionary
for key, value in dictionary.items():
print(str(key) + ": " + str(value))
# Or...
print("%s: %d" % (key, value))
# loop from 0 to n
for i in range(0, 10):
print(i, end="") # prints 0 - 9
# while
x = 0
while x < 10:
x += 1
if 1 == 2:
# Never true
# if dict contains (also works for lists)
if "other_thing" in dictionary:
# True
# Dict does not contain
if "test" not in dictionary:
# True