What Is a Function?
A function is a reusable block of code you give a name. Instead of copying the same code in multiple places, write it once and call it whenever you need it.
def greet():
print('Hello!')
print('Welcome to OKSTEM!')
greet() # call it once
greet() # call it again — runs same code
Parameters and Arguments
Parameters are variables listed in the function definition. Arguments are the actual values passed when calling it.
def greet(name): # name is a parameter
print(f'Hello, {name}!')
greet('Alex') # 'Alex' is the argument → Hello, Alex!
greet('Jordan') # → Hello, Jordan!
Return Values
def add(a, b):
return a + b
total = add(5, 3) # total = 8
print(add(10, 20)) # 30
💡return vs print
A function that uses print() shows output but returns nothing. A function that uses return sends a value back that you can use in further calculations or store in a variable.