Answers for "constr python"

4

python constant

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'
Posted by: Guest on May-13-2021
0

const in python 3

You cant make a constant in Python like in other languages so just dont edit the variable and
give it a name with ALL_CAPS and a comment saying it is a constant
Posted by: Guest on March-15-2022

Python Answers by Framework

Browse Popular Code Answers by Language