0Pricing
Python Academy · Lesson

Defining and Calling Functions

Create functions with def and call them with arguments.

Introduction

Functions are reusable blocks of code defined with def. They avoid repetition and make programs easier to test and maintain.

def Keyword

def greet(name): defines a function. The body is indented. Call it with greet('Alice').
def greet(name):
    print('Hello', name)
greet('Alice')

All lessons in this course

  1. Defining and Calling Functions
  2. Default and Keyword Arguments
  3. args and kwargs
  4. Return Values and Scope
← Back to Python Academy