PYTHON MODULES
What is meant by modules . ?
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
It is a platform where we can divide our program in small parts. Why does it need? because sometimes when the line of codes increases it will be challenging to find out the code. so in python module is a platform where you can store your program is a different platform.
For Free, Demo classes Call: 02071171500
Registration Link: Click Here!
How to create a module . ?
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
There is a very simple process to create a module. it is in the following manner :
(to create it just write a code and save it as an extension .py)
Mymodule.py
Def greet():
Print(“welcome” +nm)
How to use this module . ?
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
You can use this module with the help of importing method in the following manner :
Import Mymodule
Mymodule.greet(“sneha ranbhidkar”)
Modules with variables:
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
We can create more than variables with help of modules how? lest see by below example:
Mymod1.py
Employ {
“Id” : “101”,
“Name” : “john smith”,
“post” : “software engineer”,
“salary” : “37,000”
}
For Free, Demo classes Call: 02071171500
Registration Link: Click Here!
How to call the variables . ?
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Import Mymod1
X = Mymod1 . employ [“ post ”]
Print (X)
Naming to module : :
You can re assign name to module .
Import mymod1 as mod
Y = mod . employ [ “ salary “ ]
Print (Y)
Import from module:
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Instead of calling all the functioning of module, you can call the specific function through module :
Lets see :
From mymod1 import employ
Print ( employ [ “name” ] )
For Free, Demo classes Call: 02071171500
Registration Link: Click Here!
Built in modules :
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
- platform
This module is used to see which operating system is running in your laptop.
Ex.
Import platform
A = dir ( platform)
Print ( A )
- sys
This module is used to perform or to know the operations regarding the system
Ex.
Import sys
Print ( “ you execute : “ , sys.argv[1])
Sys.maxsize
This will provide you the maximum number from the system.
Sys.exit
It will give you exit from console or from command prompt .
Sys.path
It will provide you the details regarding where you python is stored.
- math
It provide you all the mathematical operations methods in python.
For ex.
Import math
Math.pi
3.145667
Above code will show the actual value of pi which already defined in mathematics. SevenMentor is the best Python training in Pune. Python is one of the most popular, flexible programming languages today
So like this you can add many things like
Math.e
Math.radians()
Math.log()
Math.pow()
Math.avg()
Author:-
Call now!!! | SevenMentor Pvt Ltd.
© Copyright 2021 | Sevenmentor Pvt Ltd.