Familiarity-with-the-Python-Environment---Python-Files-and-Modules Familiarity with the Python Environment Python Files and Modules

Familiarity with the Python Environment Python Files and Modules

11 February 2025

Familiarity with the Python Environment : Python Files and Modules

Python allows code organization through files and modules.

Python Files
•Pyhton files have a .py extension.
•They contain Python code that be executed or imported into other scripts.

•Example file my_script.py :
df greet():
    print("Hello from Python!")
    
Python Modules
•A module is a python file containing reusable funtions and classes.
•Modules can be imported using the import statement.

•Example of importing a module:
import my_script
my_script.greet()

•Python has built-in modules like math, random and os that provide additional funtionalities.
import math
print(math.sqrt(25))

Using files and modules allows better code organizatin and reuse across projects.
 

Get In Touch