# Python Constants

> Python has no true constants, but you can get close with an Enum that nobody can reassign, or just follow the convention of naming a variable in uppercase.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2021-02-19 | Topics: [Python](https://flaviocopes.com/tags/python/) | Canonical: https://flaviocopes.com/python-constants/

[Python](https://flaviocopes.com/python-introduction/) has no way to enforce a variable to be a constant.

The nearest you can go is to use an enum:

```python
class Constants(Enum):
    WIDTH = 1024
    HEIGHT = 256
```

And get to each value using for example `Constants.WIDTH.value`.

No one can reassign that value.

Otherwise if you want to rely on naming conventions, you can adhere to this one: declare variables that should never change uppercase:

```python
WIDTH = 1024
```

No one will prevent to overwrite this value, and Python will not stop it.

That's what does most Python code you will see.
