Lazo Lab Sign up

Python Fundamentals / Functions and errors

Lesson 29 of 38

Defining functions

A function is a named block of reusable code. Define it with def, give it parameters, and call it by name.

Key points

  • def name(params):
  • Indent the body
  • Call it with name()
def greet(name):
    print(f"Salam, {name}!")

greet("Fahad")
Watch a video on thisOpens YouTube search results for “Defining functions” in a new tab

Quiz · +10 XP

Which keyword defines a function?

Log in to save progress and earn XP.