How do I create a constant in Python?

后端 未结 30 2669
既然无缘
既然无缘 2020-11-22 09:07

Is there a way to declare a constant in Python? In Java we can create constant values in this manner:

public static          


        
30条回答
  •  死守一世寂寞
    2020-11-22 09:46

    PEP 591 has the 'final' qualifier. Enforcement is down to the type checker.

    So you can do:

    MY_CONSTANT: Final = 12407
    

    Note: Final keyword is only applicable for Python 3.8 version

提交回复
热议问题