Python def Keyword

To define a function. def Indicates that what follows is a function definition. A function is a block of statements that:

  • May or may not take any parameters.
  • May or may not return anything.

Example

Python
def sayHello():
    print('Hello')

def add(a, b):
    return a + b

sayHello()
sum = add(1, 2)
print(sum)

Output

Hello
3