3.3k views
3 votes
According to the PEP 8 coding style guidelines, how should constant values be named in Python?

1) In lowercase with underscores
2) In uppercase with underscores
3) In lowercase without underscores
4) In uppercase without underscores

User Trickbz
by
8.7k points

1 Answer

0 votes

Final answer:

PEP 8 recommends naming constants in uppercase with underscores to distinguish them from regular variables.

Step-by-step explanation:

According to the PEP 8 coding style guidelines for Python, constant values should be named using uppercase letters with underscores separating words. This naming convention is part of the best practices for writing readable and maintainable code, and it helps differentiate constants from variables which use lowercase letters (potentially with underscores).

For example, a constant value representing the speed of light in a physics simulation might be written as SPEED_OF_LIGHT = 299792458. This clearly indicates that SPEED_OF_LIGHT is a constant and should not be changed throughout the program.

User Alberto Vassena
by
7.8k points