Skip to content

Functions

Parameters and results may carry type contracts. Arguments can be passed by position or by name, and parameters may have defaults.

Every function ends with a single return.

def area(width: num, height: num) -> num:
return width * height
def perimeter(width: num, height: num = 1) -> num:
return 2 * (width + height)
print(area(4, 5))
print(area(height=2, width=3))
print(perimeter(4))
Run in playground
Output
20
6
10