DEV Community

Cover image for Modules in Python
datatoinfinity
datatoinfinity

Posted on

2

Modules in Python

A Python file containing code you want to include in program use 'import' to include module (built-in or your own) useful to break up a large program to reusable separate files

Let's break this definition.

  • First we use python module of math.
  • we will make our own module of math.

simply open your code editor and write.
Here we will use python built-in module.

import math

print(math.pi)
output:

3.141592653589793

Now we will take an example of module you will create.

  1. Create a folder name "mathfunction".
  2. now make two python file name "main.py" and "math.py"
math.py

pi=3.141

def square(x):
    return x**2
 # type: ignore

def cube(x):
    return x**3


def circumference(radius):
    return 2*pi*radius
main.py

import math
y=6
print(math.pi)
print(math.cube(y))
print(math.square(y))
Output from main.py
3.141
216
36

You have seen that pi value is the value I have given it.

Redis image

Short-term memory for faster
AI agents 🤖💨

AI agents struggle with latency and context switching. Redis fixes it with a fast, in-memory layer for short-term context—plus native support for vectors and semi-structured data to keep real-time workflows on track.

Start building

Top comments (2)

Collapse
 
msnmongare profile image
Sospeter Mong'are

Thank you for sharing this. Its informative

Collapse
 
datatoinfinity profile image
datatoinfinity

Appreciated

Redis image

Short-term memory for faster
AI agents

AI agents struggle with latency and context switching. Redis fixes it with a fast, in-memory layer for short-term context—plus native support for vectors and semi-structured data to keep real-time workflows on track.

Start building

👋 Kindness is contagious

Sign in to DEV to enjoy its full potential—unlock a customized interface with dark mode, personal reading preferences, and more.

Okay