Difference Between Function and Module in python
what is module in python ?
A module is contains the logical python coded , Grouping related code into Python file and this file save with .py extension that is called Module.
Every .py file is called Python module in python
Python module is used in other application using " import ".
Example
# Create Test.py File (Or Module)
def Module(val1,val2):
# this program is add two number
Sum = val1 + val2
print(Sum)
Now we Will create Other .py file and import the test.py module in this file
Example
Import Test
Test.Module(20,30)
Output
50
What is Function ?
A Function in python is a block of code that is run whenever called in your code.
You can pass The data which is called as parameter
There are Two Types of function
- User Define Function : that is define by user
- Built-In Function : Built-in function created by default like print(),input() etc
Example
# here how we are create built in len() function and example
# len() function is used for Return the length
lst = ["dog","lion","tiger"]
x = len(lst)
Output
3
Also See