Constants in Elm

To demonstrate the use of constants in Python, here’s an example. Constants in Python can be defined by using uppercase variable names as a convention. Python does not enforce constant values strictly, but this convention helps communicate the intention.

import math

# Constants in Python are typically defined using uppercase variable names
S = "constant"
print(S)

# Constants can be declared anywhere a variable can be
N = 500000000

# Constant expressions perform arithmetic with arbitrary precision
D = 3e20 / N
print(D)

# A numeric constant has no type until it's given one explicitly
print(int(D))

# A number can be given a type by using it in a context that requires one,
# such as a variable assignment or function call. For example, here
# math.sin expects a float.
print(math.sin(N))

To run the program, put the code in a file, let’s say constants.py, and use the Python interpreter.

$ python constants.py
constant
6e+11
600000000000
-0.28470407323754404

Python does not have a dedicated build process as compiled languages do. You directly run the source code using the Python interpreter. In the above example, you can see how constants are used and managed within a Python script. Now that you understand basic constants in Python, you can explore more advanced topics in the language.