Python Beginner Cheat Sheet A4 Two Column
Python Beginner Cheat Sheet A4 Two Column
1. SYMBOLS 7. LOOPS
# Comment for i in range(3):
() Parentheses print(i)
[] Lists
{} Dictionaries count = 0
: Colon while count < 3:
; Semicolon print(count)
, Comma count += 1
'' String quotes 8. LISTS
\n New line fruits = ['apple']
\t Tab fruits.append('orange')
2. VARIABLES & TYPES print(fruits[0])
x = 5 # int 'apple' in fruits
y = 3.14 # float len(fruits)
name = 'Anna' # str 9. DICTIONARIES
is_happy = True # bool person = {'name': 'Tom'}
type(x) # check type print(person['name'])
3. OPERATORS person['age'] = 25
+ - * / # math 10. FUNCTIONS
% ** // # mod, power, floor def greet(name):
== != > < >= <= # compare print('Hi', name)
and or not # logic greet('Anna')
+= -= *= /= # assign 11. IMPORTS
4. STRINGS import math
s = 'Hello' math.sqrt(16)
s.upper() # 'HELLO'
s[0] # 'H' import random
'lo' in s # True random.randint(1, 5)
len(s) # 5 12. COMMENTS
5. INPUT / OUTPUT # single line
name = input('Name: ') '''multi-line comment'''
print('Hi', name)
6. IF / ELSE
if age >= 18:
print('Adult')
elif age > 12:
print('Teen')
else:
print('Child')