[ Web Proxy ]
URL:
Viewing: https://www.pythontutorial.net/python-basics/python-constants/ [Back]  [Original]

Python Constants
Skip to content

Python Constants

Summary: in this tutorial, you’ll learn how to define Python constants.

Sometimes, you may want to store values in variables. But you don’t want to change these values throughout the execution of the program.

To do it in other programming languages, you can use constants. The constants are like variables but their values don’t change during the program execution.

The bad news is that Python doesn’t support constants.

To work around this, you use all capital letters to name a variable to indicate that the variable should be treated as a constant. For example:

FILE_SIZE_LIMIT = 2000
print(FILE_SIZE_LIMIT)Code language: Python (python)

Try it

When encountering variables like these, you should not change their values. These variables are constant by convention, not by rules.

Summary #

Quiz #

Was this tutorial helpful ?
Yes No
Search …:

Getting Started

Python Fundamentals

Operators

Control Flow

Functions

Python List

Python Dictionary

Python Set

Exception Handling

Python Loop with Else Clause

More on Functions

Modules

File I/O

Directory

Managing Third-party Packages

Copyright © 2021 - Present, By Python Tutorial. All Rights Reserved.


Web Proxy Viewer  |  New URL  |  Original Page