How do I create a constant in Python?
In Python, a constant is typically defined as a variable that is assigned a value that should not be modified later on in the program.
In Python, a constant is typically defined as a variable that is assigned a value that should not be modified later on in the program. To create a constant in Python, you can use an uppercase variable name and assign it a value, as in the following example:
Create a constant in Python
PI = 3.14
<div class="alert alert-info flex not-prose">![]()
<span class="hidden md:block">Watch a video course</span>Python - The Practical Guide</div>
It is a convention in Python to use uppercase variable names for constants, although this is not enforced by the language itself. However it is not a language level feature and you are free to use any naming conventions and methods to make sure the variable is not modified later on in the program.