No there is not. You cannot declare a variable or value as constant in Python. Just don’t change it.
If you are in a class, the equivalent would be:
class Foo(object): CONST_NAME = "Name"
if not, it is just
CONST_NAME = "Name"
But you might want to have a look at the code snippet Constants in Python by Alex Martelli.
As of Python 3.8, there’s a typing.Final
variable annotation that will tell static type checkers (like mypy) that your variable shouldn’t be reassigned. This is the closest equivalent to Java’s final
. However, it does not actually prevent reassignment:
from typing import Final a: Final = 1 # Executes fine, but mypy will report an error if you run mypy on this: a = 2
Related Posts:
- Class constants in python
- Find the current directory and file’s directory [duplicate]
- Finding the index of an item in a list
- What does the list() function do in Python?
- raw_input function in Python
- How to execute a program or call a system command?
- Adding new column to existing DataFrame in Python pandas
- Confusion between Python and Anaconda
- How to find which version of TensorFlow is installed in my system?
- Understanding the Python ‘with’ statement
- Python ‘If not’ syntax [duplicate]
- What is the maximum recursion depth in Python, and how to increase it?
- Converting dictionary to JSON
- Saving and loading objects and using pickle
- numpy: Invalid value encountered in true_divide
- Python arrays used as indices must be of integer (or boolean) type
- What does ** (double star/asterisk) and * (star/asterisk) do for parameters?
- Conda uninstall one package and one package only
- Cannot find module cv2 when using OpenCV
- Getting TypeError: __init__() missing 1 required positional argument: ‘on_delete’ when trying to add parent table after child table with entries
- TypeError: list indices must be integers, not str (boolean convertion actually)
- ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL’s are there
- Pandas “Can only compare identically-labeled DataFrame objects” error
- ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL’s are there
- SyntaxError: multiple statements found while compiling a single statement
- How can I remove a trailing newline?
- Pycharm exit code 0
- How do you split a string in Python with multiple delimiters?
- syntaxError: ‘continue’ not properly in loop
- ValueError: all the input arrays must have same number of dimensions
- Get the data received in a Flask request
- Python function execution
- load csv into 2D matrix with numpy for plotting
- Python TypeError: cannot convert the series to
when trying to do math on dataframe - How do I do a case-insensitive string comparison?
- How to fix ‘ValueError: list.remove(x): x not in list’ error in Python
- How can I convert radians to degrees with Python?
- How to initialize a two-dimensional array in Python?
- IndexError: index 1 is out of bounds for axis 0 with size 1/ForwardEuler
- selenium – chromedriver executable needs to be in PATH
- TypeError: tuple indices must be integers, not str
- (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escape
- TypeError(“‘bool’ object is not iterable”,) when trying to return a Boolean
- Flask Template Not found
- Implementing an efficient queue in Python
- Modify the legend of pandas bar plot
- Python int to binary string?
- Full examples of using pySerial package
- Checking whether a variable is an integer or not
- Using headers with the Python requests library’s get method
- How to measure elapsed time in Python?
- Issues using Keras np_utils.to_categorical
- Flask ImportError: No Module Named Flask
- Running an outside program (executable) in Python?
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- How to install PyQt5 on Windows?
- How do I get the day of week given a date?
- TypeError: ‘dict_keys’ object does not support indexing
- Add Variables to Tuple
- What does socket binding mean?
- How to strip all whitespace from string
- Python Binomial Coefficient
- Pandas – How to flatten a hierarchical index in columns
- What is the difference between json.load() and json.loads() functions
- Viewing all defined variables
- Difference between two dates in Python
- ImportError: No module named win32com.client
- Python, how to handle the “ValueError: unsupported pickle protocol: 4” error?
- python error: TypeError: an integer is required
- Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
- Get an attribute value based on the name attribute with BeautifulSoup
- getting ValueError : “Can only tuple-index with a MultiIndex “
- ModuleNotFoundError: No module named ‘seaborn’ in Python IDE
- UnicodeEncodeError: ‘charmap’ codec can’t encode characters
- Is there a ceiling equivalent of // operator in Python?
- Groupby value counts on the dataframe pandas
- How to plot an array in python?
- If statement for strings in python?
- How to create a numpy array of all True or all False?
- How to change legend size with matplotlib.pyplot
- An equivalent function to matplotlib.mlab.bivariate_normal
- Float must be a string or a number?
- Play audio with Python
- Inheritance and init method in Python
- TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- Releasing memory in Python
- Text progress bar in terminal with block characters
- Generator expression must be parenthesized if not sole argument
- Get a Try statement to loop around until correct value obtained
- Does python have header files like C/C++?
- Making a POST call instead of GET using urllib2
- Extract first and last row of a dataframe in pandas
- Python decoding Unicode is not supported
- TypeError: got multiple values for argument
- How can I recover the return value of a function passed to multiprocessing.Process?
- Python: OSError: [Errno 2] No such file or directory: ”
- bound method Response.json of Response [200]
- TypeError: coercing to Unicode: need string or buffer