Functions
Source: 4-Functions/4.1-functions.ipynb
Start here — no coding background needed
What you will learn
Bundle steps into one reusable block with a name.
In simple words
Define with `def name():`, call with `name()`. Pass inputs in parentheses if needed.
Think of it like this
Coffee machine button: same steps every morning, you only press "espresso".
Words to know:
- def — Starts a new function
- return — Sends a result back to whoever called the function
Write a recipe once, use it many times — functions save repetition.
Easy example — run this first. Change values and press Run again.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Reference notes (from full bootcamp)
Optional — deeper detail for when you are ready
Functions in Python
Video Outline:
- Introduction to Functions
- Defining Functions
- Calling Functions
- Function Parameters
- Default Parameters
- Variable-Length Arguments
- Return Statement
Introduction to Functions
Definition:
A function is a block of code that performs a specific task.
Functions help in organizing code, reusing code, and improving readability.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): the number is even
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): the number is even
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): 6
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): Hello Anshul Welcome To the paradise
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): Hello Anshul Welcome To the paradise
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): 1 2 3 4 5 6 7 8 Anshul
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): 1 2 3 4 5 6 7 8 Anshul
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): name:Anshul age:32 country:India
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): Positional arument :1 Positional arument :2 Positional arument :3 Positional arument :4 Positional arument :Anshul name:Anshul age:32 country:India
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): 6
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): (6, 2)
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Practice test — try yourself
Write code, press Check. Wrong answer shows the correct code to copy & run.
Write function greet(name) that prints Hello, <name>! Then call greet("Rish").