Ad space (banner)
🐍Python Lessons
Lesson 20 / 69

Constants (values you agree not to change)

This lesson covers the conventional way of writing constants in Python, so you can clearly express a variable that isn't meant to be changed. It's written for anyone searching "Python constants tutorial".

Python has no dedicated syntax for constants like some other languages do, but the convention is to write the variable name in all capital letters to signal "this value isn't meant to change." It isn't enforced by the language itself, but it's a widely followed unwritten rule on real teams.

The sample code uses an all-caps variable name, MAX_SCORE, and displays its value in an f-string. Technically this variable can still be reassigned, but just by seeing the name, other developers understand the intent that it shouldn't be.

A common beginner mistake is not realizing Python has no language-level enforcement for constants. Even in all caps, the value can technically still be changed — following the "don't change this" convention is entirely up to the programmer's own discipline. Don't expect the same enforcement you'd get from const in other languages.

Because the intent is immediately clear to any reader, this convention is widely used for things like configuration values in large projects or managing API keys — often gathered together as all-caps variables in a dedicated settings file, a common real-world pattern.

Python
OUTPUT

💡 The Python engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)