Defining Functions
Functions group related logic into reusable blocks. They make code cleaner and easier to maintain.
def greet(name):
print("Hello,", name)
Returning Values
Functions can return results, allowing you to use their output elsewhere in your program.
def add(a, b):
return a + b
Default Parameters
Default parameters provide fallback values, making functions flexible and user‑friendly.
def say_hi(person="friend"):
print("Hi", person)
Multiple Return Values
Functions can return more than one value at a time, which is useful for calculations like finding both the minimum and maximum of a list.
def min_max(values):
return min(values), max(values)
My take
Functions organize code into reusable blocks. They support returning values, default parameters, and multiple outputs, making programs cleaner and more modular.
Top comments (0)