// resources
Resources
All
|
Cheatsheet
Code Example
Exercise
Template
Other
Achievement
|
Basics
Control Flow
Functions
Data Structures
Modules & Packages
Projects
Object-oriented programming
|
↑ oldest first
↓ newest first
// Code Example
for_if_pattern.py
for + if — the most common pattern in Python. The loop visits everything, the if decides what to do with each visit.
// Code Example
break_statement.py
break — stops the loop immediately. No more iterations, no more checks. The loop stops when the job is done.
// Code Example
for_else.py
for...else — else runs when the loop completes without break. Skipped when interrupted. The difference between "done" a…
// Code Example
random_module.py
random — randint() and choice(). Set the boundaries, let Python fill in the surprise.
// Code Example
while_loops.py
while — repeats as long as a condition is True. You control what changes. The loop controls when it stops.
// Code Example
while_complex_conditions.py
while with and, or, not — multiple conditions, smarter loops. All conditions matter.
// Code Example
while_true_break.py
while True + break — the infinite loop you control. Run forever, stop on purpose. Input validation is the classic use c…
// Code Example
while_random.py
while + random — the loop that stops when luck decides. Roll until you hit the target, count the attempts, never know h…
// Code Example
while_else.py
while...else — else runs when the loop completes naturally. Skipped when break interrupts. Completed or interrupted — w…
// Code Example
match_case.py
match / case — one value, many cases. Cleaner than long if / elif chains. Wildcard case _, multiple values with |, firs…
// Code Example
match_case_guards.py
match / case with guards — not just values, conditions too. Pattern captures the value, guard adds the condition. Toget…
// Code Example
nested_for_loops.py
Nested for loops — a loop inside a loop. Inner completes fully before outer moves on. Total iterations = outer × inner.
// Code Example
for_if_nested.py
for + if in nested loops — filter at the outer level, inner level, or both. break stops the current loop only.
// Code Example
while_for_nested.py
while + for — while sets the pace, for does the work. break inside for stops only the for. Each loop has its job.
// Code Example
def_function.py
def — define a function once, call it anywhere. Parentheses required, indentation mandatory, defining doesn't run it — …