Functions
Learn what functions are, how to define them, and how return values work.
Defining a Function
def greet(name: str) -> None:
"""Print a friendly greeting."""
print(f"Hello, {name}!")Calling a Function
greet("Paul")Return Values
def absolute_value(n: int) -> int:
if n >= 0:
return n
return -n
print(absolute_value(-4)) # 4Scope (Local vs Global)
Types of Functions
Last updated