How do you define a function in Python?

Experience Level: Junior
Tags: Python

Answer

To define a Python function, use keyword def.

Example:

def say_hello():
  print("Hello, I am here.")

Python for beginners
Python for beginners

Are you learning Python ? Try our test we designed to help you progress faster.

Test yourself