By importing the module you can get access to code from another module in Python. Just use the import statement to import any module in python.
How to import modules in Python?
To use the module, you have to import it using the import keyword. Let’s see examples for it:-
Import inbuild python math moudles
import math # Square root of number sqrValue = math.sqrt(25) print(sqrValue)
Custome module import example
var = "Hello main file" num = 9876543210 def greeting(name): print("Hello, " + name)
import main main.greeting("John") print(main.num)
Read more ways to import module:- Python import variable from another file
Do comment if you have any doubts and suggestions on this Python module tutorial.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.