Skip to content
Guest
← All References
Python Python 3.12 (Pyodide)

Python 3 Quick Reference

Essential Python 3 syntax, f-strings, lists, dictionaries, comprehensions, and built-in functions.

def fn(x=1): return [n for n in items if n > 0]

Core Syntax & Types

SyntaxPurposeExample
f"{var}"String formatting (f-string)f"Score: {pct}%"
if / elif / elseConditional branchingstatus = "Pass" if s >= 80 else "Fail"
for x in items:Iterate over any sequencefor i, x in enumerate(items, 1):
def fn(a, b=0):Define reusable functiondef add(a, b=0): return a + b

Collections & Built-Ins

APIPurposeExample
items[-1] / items[:3]Last item / first 3 items[10, 20, 30][-1] -> 30
d.get(key, default)Safe dictionary lookupcourse.get("level", "Beginner")
[f(x) for x in xs if p(x)]List comprehension[n * 2 for n in nums if n > 0]
set(items)Unique valueslist(set(["a", "b", "a"]))
sum() / len() / sorted()Common aggregationsround(sum(xs) / len(xs), 1)

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind