Functions
Declaring Functions
def function_name(param1: type, param2: type) -> type:
body
def add(left: int, right: int) -> int:
return left + right
The first line of code is executed, the body is skipped over, but the body is returned to later when the function call is reached.
The return data type in the header is only for documentation
Python will not automatically respect the types that you include there.
This function will actually return an integer
def difference(a: int, b: int) -> bool:
return a-b
When you call a function, a value is always returned.
Even if you forget the return statement, the special value None will be returned.
Sometimes, we want to define a function without writing its body just yet.
We use a special statement named pass to fill in the body until we're ready to write it.
Pass is a very special statement: it does absolutely nothing but take up space, telling the computer to "pass over" this line.
© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited TopPrevNext