Physical Constants

Usually physics problems will require a number of physics constants in the correct units. One should always assign a identifiable variable to these constants and not just use the number without explaining what it is. In addition, one should make clear the units and where the value comes from.

Alternatively, there are a number of packages that contain the values of common physicaL constants including scipy and astropy. In scipy many constants are callable by there commonly used variable. Many others are available put must be called by name. To get a full list of names one can use the object scipy.constants.physical_constants. Example of how this works

import scipy.constants as cons
print(f"The values of G and h are {cons.G} and {cons.h}")
print(f"A way less common constant is the electron g factor which has a value of {cons.value('electron g factor'}")


It is also possible to get constants from the astropy package; however, using it is fairly different because the constants are not returned as numbers, but as objects called Quantities that include not only the value but also the units. This allows for unit conversion and can be very helpful in complicated formula, but also can be challenging if you forget these are not numbers. Here is an example:

import astropy.constants as c
import astropy.units as u
print(f"Two electrons have a mass of {2*cons.m_e}")
print(f"That is {2*cons.m_e*u.g/} in grams")
print(f"The solar radius in cm is {solar_radius}")

Print this page