Member-only story
Interview Essential -> Package VS Namespace VS Module VS Libraries
Package VS Namespace Package VS Module VS Libraries
Non Medium Members Can Read It Here
Hello Everyone, Today, I want to cover some essential parts of the Python ecosystem we use daily. These are also concepts that most interviewers expect us to be familiar with.
I’ll start with the fundamental building blocks and gradually move toward more advanced topics.
Modules
A module in Python is a single file with a .py
extension that contains Python code. Modules can define functions, classes, and variables, and can also include runnable code. They are the fundamental building blocks of Python programs, allowing you to organize your code into manageable sections.
.
├── main.py
├── maths.py
└── __pycache__
└── maths.cpython-313.pyc
maths.py
def sum(a: int, b: int):
return a + b
def product(a: int, b: int):
return a * b
main.py
from maths import sum, product
print(sum(1, 2))
print(product(1, 2))
Modules can be executed using python3 <filename>.py
, but it is a best practice to include the if __name__ == "__main__":
check. This is because…