Language

Functions · Lesson 12 of 56

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 — try this first

Easy example — run this first. Change values and press Run again.

Python

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:

  1. Introduction to Functions
  2. Defining Functions
  3. Calling Functions
  4. Function Parameters
  5. Default Parameters
  6. Variable-Length Arguments
  7. 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.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
the number is even

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
the number is even

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
6

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
Hello Anshul Welcome To the paradise

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
Hello Anshul Welcome To the paradise

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
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.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
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.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
Expected (from notebook):
name:Anshul
age:32
country:India

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
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.

Reference example
Python
Output
Expected (from notebook):
6

Runs in your browser via Pyodide — no server. First run may take a few seconds.

Reference example
Python
Output
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").

Python