Functions

Functions are the block of statements that return the specific task.

Benefits of Using

Snippet:

def function_name(parameters): return expression

Types of Functions

Creating a functions

def func(): print("Batman")

Calling a Function

def func(): print("Batman") func()

Python function with parameters

Snippet:

def function_name(parameter: data_type) -> return_type: """Docstring""" # body of the function return expression

Example :

def add(num1: int, num2:int) -> int: """Adding the two integers""" num3 = num1+num2 return num3 num1, num2 = 5,10 ans = add(num1, num2) print(f"The addition of {num1} and {num2} results {ans}.")

Python function Arguments

def evenOdd(x): if x%2 == 0: print("Even") else: print("Odd") evenOdd(2) evenOdd(3)

Types of Arguments