Welcome To
Function


Functions In Python

The function in a python is a block of reused code . that performs a specific task. That functions makes code as more readable , reuseable and organization . the function takes as parameter as a input and return the value as output. the functions there are two types of python functions

Advantages Or Needs of Functions

Code Reuseable

Code Organization

Easy to debug

reduce the code

avoid the redundancy

Types of Functions

Built in Functions

User Define Functions

Anonymous functions

Built In Functions

The Python provides the predefined functions to code get more readable we used that code in the program .

The built in functions are predefined means the python developer already developed that functions that functions we used later in the python code. some built in functions is below

built in Functions in python

  1. type()
  2. print()
  3. Input()
  4. Max()
  5. Min()
  6. len()
  7. abs()
  8. sum()
  9. int()
  10. Float()
  11. str()
  12. complex()
  13. Id()

Type()

The Type() it is a predefine function. it is used to check the type of variable .

print()

The it is also predefine function used to print the console output on the screen

Input()

The input function is used to take the input from the user . The input takes every input as a treated as a string . then we want to convert that into our form when require.

max()

It is a mathematical operation find the maximum value in the integer.

Min()

It is a mathematical operation find the minimum value in the integer.

len()

The len() function is used find the length of the string

abs()

The abs() function is used to convert the negative value to positive value . as find the absualte value.

Id()

The Id() function is used to check the identifier value as in the collection

complex()

The complex() function is used to convert the one data type to another data type by using functions

Etc.

User Define function

The User Define function is a when user going to define the function when it is require . The user is creating the function by using the def keyword followed by function name and parameters . syntax and example in the below

Syntax

def Function_name parameters colon
# function Body
     return value

Example

def greet(name):
     return name
Result=greet("Darshan")
print(Result)

Output
Darshan

function Definition

The function is a contain the def keyword and Function_name , parameters, colon, function body. we want to create the function we definitely follow this definition .

Definition Format

def function_name parameters and colon
     return value
function statement

def the def is a keyword used to create a function as user . every user define function with start with a def keyword

Function_nameThe function name is a identifier in the python it store the data and it return the result when the function to the caller .

Parameters() it is a piece of data that function can have . it followed by colon : it specifics the end of the function

return the return is a keyword it returns the value of a function . and it sends back of the value when the function to the caller

Function Calling

We want to print the function body statements we most be call the function inside the function . when the program calls the function , program control is transferred to the called function. a called function returns control to the caller when its return statement is executed or the function is finished .

Example:
larger=max(3,4)
# the function body

Return Statement In Python

The return statement in python is returns the function data then after that data may comes when the function to the caller . The function return value is called fruitful function . followed by the expression it evaluate the expression and performs a specific task. the expression is any type like string,int,boolean, float,and other. syntax and Example in the below

Syntax

return Expression

Example

return a+b

The Void Function

The void function is a one type of function no return value . the void function can perform a specific task but does not return the value. tha python program program does not include the return statement. and the the python void function provides the multiple parameters to declare the value inside the function the we want to call that function by using a function name. Example in the below

Example

def add( a ,b):
   print('sum is', a+b)
result=add(10,20)
print(result)