Google News
logo
Python Program to Variables in module
A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py added.

To use the module, we can import the module using the import statement. Once we import the module, we can access the variables and functions defined in the module using the dot notation.

Here's an example of how to define variables in a module and access them in another Python script :

First, create a file called `mymodule.py` and define some variables :
Program :
# mymodule.py

name = "John"
age = 35

Then, in another Python script, import the module and access the variables :

# main.py

import mymodule

print(mymodule.name)
print(mymodule.age)
When you run the `main.py` script, you should see the following output :
John
35​