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.
- Create a folder name "mathfunction".
- 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.
Top comments (2)
Thank you for sharing this. Its informative
Appreciated