Skip to content

How to define a constant in Python?

A constant is a type of variable that holds values, which cannot be changed. In reality, we do not use constants in Python. There is no predefined type for a constant variable in Python. But we can use pconst library for that.

# import module
from pconst import const

# define your constants
const.LANGUAGE = "SPANISH"
const.COMPANY = 'EL GORAUGY'

# print your constants
print(const.LANGUAGE)
print(const.COMPANY)

You cannot update your constants or use del operator for the variables defined with pconst.

See also  Python code snippet - How to change help command on discord ?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.