User defined function:

1: Simple function

2: Function arguments

3: Return Function

Simple Function: def is used to create function it is a reserved keyword

def simple_function(): 
 # function is defined function name will be according to your name no space and special
# character will be use, create one time and call many times so it saves the programmer time,
	print("Function example")

simple_function()  # calling the function ,

Argument Function

def argument_function(a, b):  # function is created which is taking the argument and
 # adding it () it is called parameters, where we can pass arguments.
		print(a + b)

num = 10
num2 = 20
argument_function(num, num2)  # here we have the function, and we have passed the var in its argument
# when we execute this function then the above def defined function will be called with this given argument
argument_function(10, 10)  # it will give 20 as an output
num = 10
num2 = 20
argument_function(num, num2)  # here we have the function, and we have passed the var in its argument
argument_function(10, 10)  # it will give 20 as an output so this function will add 
# them as the use of this function is to add
def default_argument(a, b=5):  # here we have taken default value of b ,so it is called default argument ,
# so while calling this function we can pass only one value and if we pass two
# value then it will override the default value and work on current given value
		print(a + b)

n = 2
n2 = 4
default_argument(n)  # here it has taken only n that is two but we have default value 
# that is 5 so # the output of this function will be 7, but if we pass n2 in this 
# function argument then it will override the default value

Return: It is used when you only wants to store the value but wants to print according to your use so we can put condition in it.

def sum_return(a, b=5):
		c = a + b
		return c

var = sum_return(20, 30)  # now this function has added the value according to its 
# function, but it won't print but value is added now we can print according to our need,
# so now we have stored the value in a variable and can be printed by the print command
print(var)  # 50 , 50
print(sum_return(20, 30))

def square(x):
		return x * x, x * 2  # it will return multiple value,

s = square(5)  # square and multiply with 2
print(s)
s = square(5)  # square and multiply with 2
print(s)

MODULE :

A Python module is a file containing Python definitions and statements. A module can define functions, classes, and variables. A module can also include runnable code. Grouping related code into a module makes the code easier to understand and use. It also makes the code logically organized.

Types of Module:

Predefined Module and User Defined Module (For reuse purpose, it will be create in another page and should be imported)

import module
print(module.sum(12, 12))
# we have created a module file and it is being imported, and we are using the sum 
# function of the module and we are calling sum function from the module and passing the value
print(module.mul(2, 3))
from module import sum  # another way to import module but calls only sum function
print(sum(2, 3))

from module import *  # * it calls all the function which is present in the module

print(sum(2, 3))
print(mul(4, 5))

import module as m  # we can give an alias or short name to our module in this way

print(m.sum(3, 7))

Math Module: Math module is an inbuilt module.

import math
x = -19.3
print(math.ceil(x))  # ceil will return upper value
print(math.floor(x))  # floor it will return lower value
print(math.fabs(x))  # fabs will return positive value, it converts negative value to positive value
x = 4
print(math.factorial(x))  # factorial it will return the factorial of the value, 
# as this factroial function is made somewhere in math module.
l = [12.5, 23, 44, 66]
print(math.fsum(l))  # fsum function gives the sum of the elements present in the tuple or list
print(math.sqrt(x))  # sqrt it will return square root of the value