constants

Defining constants in python class, is self really needed?

Defining constants in python class, is self really needed? Question: I want to define a set of constants in a class like: class Foo(object): (NONEXISTING,VAGUE,CONFIRMED) = (0,1,2) def __init__(self): self.status = VAGUE However, I get NameError: global name ‘VAGUE’ is not defined Is there a way of defining these constants to be visiable inside the …

Total answers: 5

How do I create a constant in Python?

How do I create a constant in Python? Question: How do I declare a constant in Python? In Java, we do: public static final String CONST_NAME = "Name"; Asked By: zfranciscus || Source Answers: You cannot declare a variable or value as constant in Python. To indicate to programmers that a variable is a constant, …

Total answers: 44