Free Python course. Sign Up for tracking progress →

Python: Constants

Some data never change - for example, mathematical constants. Take π as an example. It is always 3.14 and cannot change. Python uses constants to refer to this kind of data:

PI = 3.14
print(PI)  # => 3.14

A constant is created in the same way as a variable. The only difference is that constants are usually named with capital letters have and _ as a separator between words. A constant, like a variable, can be used in any expression.

Instructions

Create a constant DRAGONS_BORN_COUNT and write the number 3 in it, which is the number of dragons born to Daenerys.

Definitions

  • Constant a way to store information and name it for later use in code; constants cannot be changed, unlike variables.