how to define a constant in python

# You can't, just use uppercase to identify

0
6
CGR 110 points

                                    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'

0
0
3.33
5
Salem874 130 points

                                    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.

3.33 (6 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
does python have constants can we make a constant variable in python how to make variable constant in python class constant python pyhton constant class python constants tutorial can you declare constants at function level in python create constant in python file define class constant python constant variables python how to create a constant variable in pyhton python constant values python create constant variable how to write constants in python python named_constants how to declare constants in python variable and constant python how to create a constant variable in python constant in python3 constant python class constant class python how to get all constants in function in py define constant function python what are constants in python import constant in python what is constant is python whats a constant in python how to make constante variable pyhonm python class Constant python constants class create constant class in python how to import constants in python what is constant in python python string constant class python "local constant" how to do e constant in python python where to store constants python create a constant constant e python python declaring constants in class can you make constant variables in python python constant declaration define constant in python class make a constant variable in python class constants python create a constant python what is constant variable in python constant = a function in python python constants in class how to make a constant name in python python what is a constant python constants module constant python function call python class constants constant e in python how to set constants in python python create a constant variable in a module const variables python class of constants python where to store constant variable in python python declare a constant for all my functions python declare a constant out of function how to write e constant in python add_constant function in python declaring constants in python make variable constant python python constant class how to make a value constant in python python constante define constants python create constant python python constants syntax defining constants variables in python constants import python what is a constant python make const python what is python 3 constant python 3 constant documenting constants in python why does python use constants make variables constant python where to store constants python what should be a constant python python define a constant how to write constant in python python constant variables constant value name in python constant values named in python python constantts declaring constant variables in python constantes en python what is considered a constant variable in python constants in pyhton constant and variable in python how to create a constant var in python programming constants in python python declaring constants constants in py constant values python import constants in python how to use constant in python how to define a constant value in python can we define constants in python how constant values named in python python variable constant how to make a string constant in python how to use constant variable in python constant to variable python constant module in python how we define constant in python constant tou in python e constant in python python constant data how to take var constant in python how to print a constant in python constant in class python declare a constant in python calculate the constant python what is the constant in python named constant python how to create a constant in python python store constant best way to make a constant in python python import constants should we define constant in function in python how to declare constant in python and call it how to name constants in python python make constant python e constant constants variables in python define constant python where to put constants python can you make a constant in python constant variable syntax in python define a constant python how to properly use constants in python creating constants in python how to declare constant in python declare constant python how to name constant values in python how to make constant variable in python define the constant e in python programming python constants variables what is a constant in python python constant example python create constant python create a constant.py how should constant bv=values be named in python python string constants constants values in python constant number in python how to declare constant variable in python how to create constants in python initialise a constant in python where do you set constants in python how to create constant in python making a constant in python python create constants for values constante python constants and variables in python what is a named constant in python python declare a constant how should constant values be named in python python variables and constant constantes python python constant syntax how to define constant in python can we create constant in python how to declare a constant in python how should constants be named in python define constant in python constent in python how to make a constant in python are immutable variables equivalent to constants in python string module const python string const python how to declare a constant python how should constant value be named in python how to declare a constant variable in python python const variable python global constants constant meaning in python how to decleare const in python python declare constant is it possible to make a constant variable in python python global constant how to define a variable as constant in python const variable python how to create const in python is is a constant variable in python what is a constant variable in python examples what is a constant variable in python const value in python defining constants in python how to make a variable constant in python python create constant d const var python how to create constant integers in python constant and let used in python python file of constants Constants in python are identified by which one of the following features constant values be named in python how to declare const in python constants python name constant values in python example of a constant in python how to define a variable in python constant variable in python constant variable in pythoon const in puthon how to declare a aconstant in python python constan HOW TO DEFINE CONSTANTS INPYTHON python constant { } python const { } can we make a constant in python constant python example how to define a constant in python for in python constants constant in python example cosnt varible in python python variable vs constant create const python constc in python python list of constants declare constant in python constant values in python python assign constant how should you assign constant variables in python python define constant pytohn const python how to make constants constant file python constant value in python constant variables in python constant python python constant constant in python python set unchangeable variable py constant var py const var python define constants python constants python how to make a constant value python constant variable python function constant variable how to write a constant in python where do you define a constant in python? define constants in python python make constant public how to make a const in python how to define constants in python const in python create constant in python python make a number constant const value name in python python 2 const python set constant python make static constant const python python const how to declare constany in python constants in python constant variable python python const delcare consatnt python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source