capypad
0 day streak
python / beginner
Snippet

Defining Functions

Functions are reusable blocks of code. They can take inputs (parameters) and return a result using the return keyword.

snippet.py
python
1
2
3
4
5
def calculate_area(width, height):
return width * height
 
result = calculate_area(5, 10)
print(f"Area: {result}")
Breakdown
1
def calculate_area(width, height):
Defines a function named calculate_area with two parameters.
2
return width * height
Calculates the product and sends it back to the caller.
3
result = calculate_area(5, 10)
Calls the function with specific values and stores the result.