Cheat Sheets

Python Beginner Cheat Sheet: Variables, if/for, Functions & First Scripts

By ArpaNeuro Team September 24, 2026
Python beginner cheat sheet

A beginner Python cheat sheet is the REPL and a .py file: assignment, types you can print, if/for, and def. Run python hello.py. Do not start with machine learning notebooks until you can write a loop and a function without copying.

This Python cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.

Quick reference

  • Run: python hello.py or py hello.py on Windows. REPL: python then expressions.
  • Print: print("hi"). Commas add spaces. end="" to skip newline.
  • Variables: name = "Ada", n = 3. Names are snake_case.
  • if: if n > 0: elif/else. Colon and indent.
  • for: for item in items: and for i in range(5):.
  • while: while n > 0: plus break/continue. Avoid infinite loops.
  • def: def add(a, b): return a + b.
  • input: input("Name: ") returns a string — wrap int(...) for numbers and catch ValueError.

Copy-paste examples

First script: total a list of prices

Save as total.py and run it. Convert input with int only after you know it is digits.

def total(prices: list[int]) -> int:
    s = 0
    for p in prices:
        s += p
    return s

raw = input('Prices separated by commas: ')
parts = [p.strip() for p in raw.split(',') if p.strip()]
nums = [int(p) for p in parts]
print('Sum =', total(nums))

Common mistakes

  • Copy-pasting Jupyter cells without understanding def.
  • Comparing strings and numbers ("3" == 3 is False) after input.
  • Using tabs in one file and spaces in another.
  • Naming a file random.py and shadowing the standard library.

FAQ

  1. Do I need an IDE? Helpful (VS Code, PyCharm). Not required. A terminal and a text editor work.
  1. Python 3 or 2? Python 3 only. Ignore tutorials that print without parentheses as a statement.
  1. When do I learn Django/Flask? After functions, virtualenv, and pip. Then a tiny Flask route or Django tutorial — not both at once.

Related Python cheat sheets

Build with this stack

When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.

Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.

← All Articles Get a Quote →