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
- Defining and Calling Functions
- Default and Keyword Arguments
- args and kwargs
- Return Values and Scope