📜  python 常量 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:43.402000             🧑  作者: Mango

代码示例1
class CONST(object):
    __slots__ = ()
    FOO = 1234


CONST = CONST()

print(CONST.FOO)  # 1234

CONST.FOO = 4321  # AttributeError: 'CONST' object attribute 'FOO' is read-only
CONST.BAR = 5678  # AttributeError: 'CONST' object has no attribute 'BAR'