Python

Defining Functions

Functions

Functions are reusable blocks of code.

Syntax

def function_name():
    # code here
    pass

Call the function

function_name()

Example

def greet():
    print("Hello!")

greet() # Prints: Hello!

Your Task

Create a function called say_hello that prints "Hello, Python!" then call it.

script.py
Loading PYTHON engine...
Downloading Python… (one-time, ~10 MB)

Downloading Python… (one-time, ~10 MB)

This runs entirely in your browser and is cached for next time.