Skip to content

Python constant naming convention

  • by

Python’s constant naming convention is to use all uppercase letters and underscores to separate words. This is not enforced by the language itself, but it is a convention that is widely followed by the Python community or other programming languages.


Python does not have a true constant data type, so you can technically reassign a value to a variable defined as a “constant”. However, following the convention of using all uppercase letters and underscores to name constants can help indicate to other developers that the variable should not be modified.

Python constant naming convention examples

Simple example code naming convention in Python for variable and function.




Python constant naming convention

David Goodger (in “Code Like a Pythonista” here) describes the PEP 8 recommendations as follows:

  • joined_lower for functions, methods, attributes, variables
  • joined_lower or ALL_CAPS for constants
  • StudlyCaps for classes
  • camelCase only to conform to pre-existing conventions

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.