Functions
Functions are reusable blocks of code that perform a specific task.
Defining a Function
def greet(name):
print(f"Hello, {name}!")
Calling a Function
greet("Alice")
Return Values
Functions can return values using the return
statement:
def add(a, b):
return a + b
result = add(2, 3)
print(result)
Try writing your own functions!
← Previous: Control Flow | Next: Lists and Tuples → |
---|