Python Modules
Python Tutorial » Python Modules
Modules make refer to a file containing Python statements and definitions.
A file containing Python code, for example: my_file_name.py is called a module, and its module name would be example. We use modules like many other programs to break down large programs into small one manageable and organized files.
Create a Module
Creating a python module just save the code you have in a file with extension .py:
Example: Save the code below in a file named example.py
Output:
def add(a, b):
#This program adds two
#numbers and return the result
result = a + b
return result
#This program adds two
#numbers and return the result
result = a + b
return result
Output:
How to import modules in Python?
We use "import" (without quotes) keyword to do this. To import our module my_file, we type the following:
Example:
import my_file
Output:Python import statement
We can import a module using the import statement and access the definitions inside it using the dot operator as described above.
Example:
The value of pi is 3.14159
import math
print("The value of pi is", math.pi)
Output:The value of pi is 3.14159
Import with renaming
To import a module by renaming type the following code:
Example: Create an alias for my_file called filexx:
import my_file as filexx
a = mx.person1["age"]
print(a)
Output:a = mx.person1["age"]
print(a)
Python Modules : location, list, vs packages, location linux, and packages, index, path, exercices, vs fanction, in rust
Python Modules - python
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.