Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to define a constant in python

You can't define a constant in Python unlike in other language, hence you can 
just make the variable all CAPS and add a comment using '#' saying that this is 
a constant variable.
Comment

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'
Comment

PREVIOUS NEXT
Code Example
Python :: python list to string without brackets 
Python :: python get string from decimal 
Python :: python find all elements of substring in string 
Python :: python for else 
Python :: clahe opencv 
Python :: cannot safely cast non-equivalent float64 to int64 
Python :: python remove empty list 
Python :: create alinked list inb pyhton 
Python :: python selenium get text of div 
Python :: how to get pygame key 
Python :: how to use google sheet link in pandas dataframe 
Python :: import word_tokenize 
Python :: read page source from text file python 
Python :: how to read xlsx file in jupyter notebook 
Python :: Python Tkinter Canvas Widget 
Python :: python datetime strftime 
Python :: adf test python 
Python :: pickling and unpickling in python 
Python :: isistance exmaple 
Python :: python exceptions 
Python :: start virtual environment python 
Python :: python binary tree 
Python :: how to drop a column in python 
Python :: python sorted dictionary multiple keys 
Python :: python turtle commands 
Python :: hide code in jupyter notebook 
Python :: .encode python 
Python :: twitter bot python 
Python :: python remove consecutive spaces 
Python :: pyautogui press 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =