Skip to content

Import constants Python

  • by

Use import statement to Import constants in Python. If you want to import all the constants from the constants module, you can use the * operator like this:

import constants
#OR
from constants import *
#OR
from constants import PI, GRAVITY

Import constants Python example

Simple example code import constants from another module using the import statement.

from constants import *

print(PI)
print(GRAVITY)
print(SPEED_OF_LIGHT)

Output:

Import constants Python

Do comment if you have any doubts or suggestions on this Python import topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading