Python Tools & Reference
Quick-access syntax cheat sheet, code examples, and common mistakes to avoid.
Variables & Data Types
x = 5
Assign a value to a variable
name = "Alex"
Text enclosed in quotes
age = 25
Whole number without decimals
price = 9.99
Number with a decimal point
is_active = True
True or False value
int("5") / str(10) / float("3.14")
Convert between data types
Input & Output
print("Hello")
Display output to the console
input("Enter name: ")
Get user input as a string
f"Hi {name}"
Insert variables into strings with f-strings
Operators
+ - * / // % **
Math operations: add, sub, mul, div, floor div, mod, power
== != > < >= <=
Compare values, returns True or False
and or not
Combine boolean expressions
= += -=
Assign and update variable values
Control Flow
if x > 0:
Run code only when condition is True
if x > 0: … else: …
Choose between two paths
if …: elif …: else:
Choose among multiple conditions
for item in list:
Iterate over a sequence of items
while x > 0:
Repeat as long as condition is True
break / continue
Exit loop early or skip to next iteration
Functions
def greet(name):
Define a reusable block of code
return value
Send a result back from a function
greet("Alex")
Execute a function with arguments
len() / type() / range()
Common built-in functions for length, type, and ranges