Skip to main content

Function

Defining a function:

def greeting():
name = "Pranab Das"
print("Good morning " + name)

Later calling the function to print the greeting:

greeting()

Function with argument:

def greeting_new(name):
print("Good morning", name)

greeting_new("Pranab")

Some mathematical operations:

def add_two_numbers(input_1, input_2):
result = input_1 + input_2
return result

add_two_numbers(23, 43)

Get arbitrary number of input in a function:

def get_biggest_number(*args):
return max(args)

get_biggest_number(2, 4, 1, 8)