What is function , function definition and function calling in python?
Functions
A function is a block or package of organized , reusable lines of code for later execution.
Functions provide modularity to the script by breaking huge codes in small modules.
This helps to avoid repetition and increases re-usability.
Python provides various built-in functions like int(), sqrt(), list(), type() etc.
We can also create own functions in python, this is termed as user defined functions.
Function Definition
In python we can define a function by mentioning function name and statements.
Function definition begins with def keyword followed by function name, parentheses and colon.
We can add parameters in parentheses if required.
Later we can add required statements in code block.
Syntax
def func_name(parameters): statement(s)
Here,
def is a keyword used for defining function.
func_name can be any appropriate name given to the function.
parameter is optional.
Function Calling
In python we can call a defined function using its function name and arguments if any.
Function calling involves giving input and it will return a value.
When we call a function we invoke the function to get executed.
We can pass more than one argument in the function.
Function will pass that argument in code block and will return the result called as return value.
Syntax
func_name(arguments)
Here,
func_name will be name given in the function definition.
argument is optional and is mentioned only if parameter is present in definition.
Example of function definition and function calling
""" Author : ITVoyagers (itvoyagers.in)
Date :31st August 2020
Description : Program for showing function definition and function calling.
"""
#function definition
def name_of_fruit(x):
print("name of fruit is ", x)
#function calling
name_of_fruit(“peach”)
Output

Type Conversion functions in Python
Python supports many built-in functions for conversion of values from one datatype to another data type.
Such conversion is also called as coercion.
Python provides type() to check the data type of a value denoted by variable.
All the type conversion functions returns new object representing the converted value.
When functions like int(), str(), list() etc are used to change values to integer, string, list etc, are called as type conversion function
Example of type conversion function in python
""" Author : ITVoyagers (itvoyagers.in)
Date :31st August 2020
Description : Program for type conversion function in python.
"""
>>> a=1 >>> str(a) '1' >>> t=('i','t','c','s') >>> str(t) "('i', 't', 'c', 's')" >>> list(t) ['i', 't', 'c', 's'] >>> set(t) {'i', 't', 's', 'c'} >>> z=54.35 >>> int(z) 54 >>> x=88 >>> float(x) 88.0 >>>
Rules to define function name
- Function names are case sensitive
- Function names can be alphanumeric
- Function name can never begin with number
- Keywords can never be used as function name
- Avoid have same name for variable and function
- Function name should begin with letters (a-z,A-Z) or Underscore (_)
- No spaces are allowed in function name
- No special symbols are allowed apart from underscore(_)
- Function name can be of any length
Points to remember
1. Header is the first line of function definition and it has to end with a colon.
2. After header, rest of the body of function can be defined but that must be in indents.
3. If the parentheses is empty it indicates that the function does not contain arguments.
4. Code block can have another function inside it or even simple print statement as per requirement.
Example of function definition in python
""" Author : ITVoyagers (itvoyagers.in)
Date :31st August 2020
Description : Program to define function in python.
""" #function definition def details(): x=input("Enter your name ") print("name is ", x)
Output

For other python basics related posts:
For other advanced python related posts:
Yοur method of telling the whole thing in this piece of writing is in fact good, aⅼl
cɑn without dіfficulty be aware of it, Thanks a lot.