Skip to main content

Cheatsheet

This page is a quick reference for the most important concepts used in this workshop.

Variables

x = 10
name = "Alice"

Data types

age = 22          # int
height = 1.75 # float
name = "Alice" # string
is_student = True # boolean

If statements

if x > 5:
print("big")
else:
print("small")

Loops

for i in range(5):
print(i)

while x < 10:
x += 1

Functions

def greet(name):
return "Hello " + name

Lists

numbers = [1, 2, 3]
print(numbers[0])

Dictionaries

user = {"name": "Alice", "age": 22}
print(user["name"])

Common patterns

Input from user

value = input("Enter something: ")
number = int(value)

Random number

import random
number = random.randint(1, 100)

Basic loop with condition

while True:
break