// 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
def_function.py
def — define a function once, call it anywhere. Parentheses required, indentation mandatory, defining doesn't run it — …
// Exercise
banner.py
Banner — def in action. One function, consistent output, call it as many times as you need. "=" * len(title) fits the b…
// Code Example
parameters.py
Parameters — pass values into a function, function uses them. One function, many possible inputs. Parameter in definiti…
// Code Example
default_parameters.py
Default parameters — a fallback value when you don't pass one. Required parameters first, defaults after. Override when…
// Exercise
username_generator_2.py
Username Generator rewritten with parameters — no input() inside. Pass what changes, keep what stays. Default prefix in…
// Exercise
bmi_calculator_2.py
BMI Calculator rewritten with parameters — no input() inside. Pass weight and height, function calculates and prints. C…
// Code Example
return_statement.py
return — send a value back to the caller. Store it, print it, pass it on. First return reached stops the function. No r…
// Exercise
username_generator_3.py
Username Generator with return — the value is free. Store it, print it directly, pass it to another function. Three way…
// Exercise
bmi_calculator_3.py
BMI Calculator with return — three functions, three jobs. Calculate, categorize, print. return connects them, each can …
// Code Example
scope.py
Local vs global — where variables live. Local dies with the function, global is readable everywhere. Use return to get …
// Code Example
multiple_return_values.py
Multiple return values — return a, b packs two values, x, y = function() unpacks them. Order matters. Use only what you…
// Code Example
try_except.py
try / except — handle errors gracefully. Wrap code that might fail, catch specific errors, program continues. No crash.
// Code Example
try_except_else_finally.py
try / except / else / finally — the full picture. else runs on success, finally always runs. Use only what you need.
// Code Example
raise_statement.py
raise — throw your own errors. Enforce your function's rules. as e gives access to the message. Always pair with try / …
// Exercise
bmi_calculator_4.py
BMI Calculator with error handling — get_input() validates, calculate_bmi() calculates, get_category() labels. Three fu…