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 dataframe to excel 
Python :: image blur in python 
Python :: how to delete previous message using discord.py 
Python :: input function in python 
Python :: jupyter change cell to text 
Python :: tk is not defined python 3 
Python :: how to get table schema sql pyodbc 
Python :: radians in python turtle 
Python :: Rectangle with python 
Python :: return max value in list python 
Python :: text animation python 
Python :: read ms word with python 
Python :: installing required libraries in conda environment 
Python :: how to convert python to exe 
Python :: how to add array in python 
Python :: list reverse method in python 
Python :: python string remove whitespace 
Python :: python for web development 
Python :: raspi setup gpio 
Python :: Get request using python requests-html module 
Python :: get all different element of both list python 
Python :: reversed() python 
Python :: python turtle delay 
Python :: strip in split python 
Python :: input function python 
Python :: while loop py 
Python :: gridsearch cv 
Python :: loginrequiredmixin django 
Python :: know the type of variable in python 
Python :: multiple figures matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =