PyStart

Python Tools & Reference

Quick-access syntax cheat sheet, code examples, and common mistakes to avoid.

Variables & Data Types

Variable
x = 5

Assign a value to a variable

String
name = "Alex"

Text enclosed in quotes

Integer
age = 25

Whole number without decimals

Float
price = 9.99

Number with a decimal point

Boolean
is_active = True

True or False value

Conversion
int("5") / str(10) / float("3.14")

Convert between data types

Input & Output

Output
print("Hello")

Display output to the console

Input
input("Enter name: ")

Get user input as a string

Format
f"Hi {name}"

Insert variables into strings with f-strings

Operators

Arithmetic
+ - * / // % **

Math operations: add, sub, mul, div, floor div, mod, power

Comparison
== != > < >= <=

Compare values, returns True or False

Logical
and or not

Combine boolean expressions

Assignment
= += -=

Assign and update variable values

Control Flow

if
if x > 0:

Run code only when condition is True

if…else
if x > 0: … else: …

Choose between two paths

if…elif…else
if …: elif …: else:

Choose among multiple conditions

for
for item in list:

Iterate over a sequence of items

while
while x > 0:

Repeat as long as condition is True

break / continue
break / continue

Exit loop early or skip to next iteration

Functions

Define
def greet(name):

Define a reusable block of code

Return
return value

Send a result back from a function

Call
greet("Alex")

Execute a function with arguments

Built-in
len() / type() / range()

Common built-in functions for length, type, and ranges