Skip to main content

Posts

Functions & Modules

Functions: A group of statements into a single logical unit is called as  function. Functions are used to perform the task. Function is not called automatically. Function body is executed whenever we call the function Function can be called any no. of times. Syntax: def function_name():        =============        ============= Advantages of Functions: 1) Modularity 2) Reusability Example: def display():       print("Welcome") display() display() display() Functions are divided into 4 categories: 1) Functions with arguments with return value. 2) Functions with arguments and without return value. 3) Functions without arguments and with return value. 4) Functions without arguments and without return value. Examples: def add(a, b):        return a+b def sub(a, b):        print(a-b) def mul():        a=5        ...