Programming

Python Accessible Cheat Sheet

A screen-reader-friendly quick reference for Python syntax, built-in functions, and common patterns.

Printing and comments

Use print("Hello") to display text. Anything after a hash symbol on a line is a comment and is ignored when the program runs.

The print function accepts several values separated by commas, and it puts a space between them: print("Age:", age).

Variables and data types

Create a variable by writing a name, an equals sign, and a value. For example: count = 10, price = 9.99, name = "Priya", is_ready = True.

The common types are string for text, int for whole numbers, float for decimals, bool for True or False, list for ordered collections, and dict for key and value pairs.

Convert between types with int(value), float(value), and str(value).

Control flow

An if statement makes a decision. Write if condition:, then indent the block by four spaces. Use elif for extra conditions and else for the fallback.

A for loop repeats over a sequence: for item in my_list:. A while loop repeats while a condition stays true: while count < 5:.

Use break to leave a loop early and continue to skip to the next round.

Functions and useful built-ins

Define a function with def add(a, b): and return a result with return a + b. Call it by name: total = add(2, 3).

Handy built-in functions include len(x) for length, range(n) for a sequence of numbers, sum(list) to add numbers, min and max for extremes, and sorted(list) to order items.