Title here
Summary here
Our example will demonstrate the use of constants. In the provided example, we’ll declare a few constants and perform arithmetic operations on them. Here’s the full source code.
import math
# Declares a constant value
S = "constant"
def main():
print(S)
# A constant statement can appear anywhere a var statement can.
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, such as by an explicit conversion.
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))
if __name__ == "__main__":
main()
To run the program, save the code in constants.py
and use python
to execute it.
$ python constants.py
constant
6e+11
600000000000
-0.28470407323754404
Now that we can run and understand the basics of constants, let’s learn more about the language.