Skip to content

Python constant variable

  • by

In Python, there is no true constant variable but you can simulate constant behavior using uppercase variable names to indicate to other programmers that the variable should not be changed.

FILE_SIZE_LIMIT = 2000

The constant variable holds values, which cannot be changed.

Python constant variable example

A simple example code defines a constant PI like this.

PI = 3.14159

print(PI)

Output:

Python constant variable

Do comment if you have any doubts or suggestions on this Python constant 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

Your email address will not be published. Required fields are marked *