A constant is an identifier whose value cannot be changed throughout the execution of a program whereas the variable value keeps on changing.
There are no constants in Python, the way they exist in C and Java.
In Python, It is not possible to define constant whose value can not be changed.
In Python, Constants are usually defined on a module level and written in all capital letters with underscores separating words but remember its value can be changed.
Ex:-
PI
TOTAL
MIN_VALUE
# A constant is a type of variable whose value cannot be changed. | |
# constants are written in all capital letters and underscores separating the words | |
# In reality, we don't use constants in Python. The globals or constants module is used throughout the Python programs. | |
- constant.py | |
PI = 3.14 | |
GRAVITY = 9.8 | |
- main.py | |
import constant | |
print(constant.PI) | |
print(constant.GRAVITY) | |
Rules and Naming Convention for Variables and constants | |
# Constant and variable names should have a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore (_). For example: | |
snake_case | |
MACRO_CASE | |
camelCase | |
CapWords | |
# Create a name that makes sense. For example, vowel makes more sense than v. | |
# If you want to create a variable name having two words, use underscore to separate them. For example: | |
my_name | |
current_salary | |
# Use capital letters possible to declare a constant. For example: | |
PI | |
G | |
MASS | |
SPEED_OF_LIGHT | |
TEMP | |
# Never use special symbols like !, @, #, $, %, etc. | |
# Don't start a variable name with a digit. |















Iβm a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND