🔍 Quick Lesson: What Are Functions?
Functions in Python are reusable blocks of code that perform a specific task. They help organize your code and make it more efficient.
- Define a function using the
def
keyword. - Call a function by using its name followed by parentheses.
- Functions can take parameters and return values.
Using functions allows your programs to be cleaner, more modular, and easier to understand.
Use the links above to learn how to define and call functions!
💡 Examples
Defining a function:
def greet():
print("Hello, wizard!")
Calling the function:
greet()
Function with parameters and return value:
def add(a, b):
return a + b
result = add(3, 5)
print(result) # Output: 8