Ram

Lesson 6 of 19

Functions

Group reusable logic into named functions.

Introduction

Functions make programs easier to organize, test and reuse.

Python defines functions with the def keyword and can return values to the calling code.

Key insight

Group reusable logic into named functions.

Example

def greet(name):
    return f"Hello, {name}!"

print(greet("Asha"))

This example shows the core functions idea in a small, runnable program.

Real-world example

Functions appears in everyday application code, scripts and APIs.

Test yourself

2-question check

1

What is the main idea in Functions?

2

Where can functions be useful?

Ready to check your understanding?

Answer every question, then submit your quiz.

Try it yourself

Python compiler

Runs in your browser. Nothing is sent to a server.

Output appears here

First run downloads the Python runtime, so it may take a moment.

Practice challenge

Write a function that returns the square of a number.

Previous
Next