Previous

Functions

1 / 6
Next

Functions allow you to package code into reusable blocks. In Python, you define a function using the def keyword followed by the function name and parentheses.

def greet():
  print("Hi there!")

This defines a function called greet that prints a message. The code block within the function is indented.

To execute the function's code, you must call it:

greet()
Send

Function definitions

Hint
Beginner

Define a function called hello_world that prints "Hello, world!".

Also call the function in your script.

Help
Solve
Reset
Run
Submit
 

Test results

Test result #
Expected output
Your output

Your email has been verified!