Python Module Variables
Variables in Module
The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc):
Example
Save this code in the file mymodule.py
person1 = {
"name": "John",
"age": 36,
"country": "Norway"
}
"name": "John",
"age": 36,
"country": "Norway"
}
Example
Import the module named mymodule, and access the person1 dictionary:
import mymodule
a = mymodule.person1["age"]
print(a)
Try it Yourself »
a = mymodule.person1["age"]
print(a)
Related Pages
Python Modules Tutorial Create a Module Renaming a Module Built-in Modules Using the dir() Function Import From Module