In scientific and mathematical calculations, universal constants such as π (pi) or the gravitational constant G are frequently needed. Whether it's determining the area of a circle or calculating gravitational force, having reliable constants readily available helps streamline the process.
Scipy.constants module in SciPy allows users to access collection of mathematical, physical and unit conversion constants effortlessly with a single line of code.
Accessing Constants
Constants can be accessed using the format:
scipy.constants.CONSTANT_NAME
Below listed constants are commonly used:
import scipy.constants as const
print("Pi:", const.pi)
print("Golden ratio:", const.golden_ratio)
print("Speed of light:", const.c)
print("Gravitational constant:", const.G)
print("Gas constant (R):", const.R)
print("Boltzmann constant:", const.k)
print("Proton mass:", const.proton_mass)
Output

Finding Constants
Use the find() method to search for constants by keyword.
import scipy
res = scipy.constants.find("electron")
print(res, end='\n')
Output

Physical Constants: Value, Unit and Uncertainty
Not only the value but also the corresponding unit and the degree of uncertainty of a physical constant can be retrieved using physical_constants dictionary from scipy.constants.
scipy.constants.physical_constants['name']
import scipy.constants as const
# This return a tuple(vslue, unit, uncertainty)
print(const.physical_constants['alpha particle mass'])
Output
(6.644657345e-27, 'kg', 2.1e-36)
Example: Sample Use Cases
import scipy.constants as const
# Area of a circle using pi
def area_of_circle(r):
return const.pi * r * r
# Gravitational force
def force_gravity(M, m, dist):
return (const.G * M * m) / (dist ** 2)
print("Area of Circle:", area_of_circle(5))
print("Gravitational Force:", force_gravity(10, 5, 1))
Output

Commonly Used Constants in SciPy
| Constants | Description |
|---|---|
| pi | Mathematical constant π |
| golden_ratio | Golden ratio |
| c or speed_of_light | Speed of light in vacuum |
| G | Gravitational constant |
| E | Elementary charge |
| R | Molar gas constant |
| alpha | Fine-structure constant |
| N_A | Avogadro constant |
| k | Boltzmann constant |
| sigma | Stefan-Boltzmann constant σ |
| m_e | Electron mass |
| m_p | Proton mass |
| m_n | Neutron Mass |
| h or Planck | Planck Constant |
Unit Conversion Constants
Mass Units:
| Unit | Description |
|---|---|
| gram | One gram in kilograms. |
| grain | One grain in kilograms. |
| pound | One Pound in kilograms. |
| ounce | One Ounce in kilograms. |
| automic_mass | Atomics mass constant in kilograms. |
Time Units:
| Unit | Description |
|---|---|
| minute | One minute in seconds. |
| hour | One hour in seconds. |
| day | One day in seconds. |
| year | One year in seconds. |
Length Units:
| Units | Description |
|---|---|
| inch | One inch in meters. |
| foot | One foot in meters. |
| yard | One yard in meters. |
| pt | One point in meters. |
| micron | One Micron in meters. |
Pressure Units:
| Units | Description |
|---|---|
| atm/atmosphere | The standard atmosphere in pascals. |
| bar | One bar in Pascals. |
| torr | One torr(mmHg) in pascals. |
Area Units:
| Units | Description |
|---|---|
| hectare | One hectare in square meters. |
| acre | One acre in square meters. |
Speed Units:
| Units | Description |
|---|---|
| kmh | Kilometer per hour in meter per second. |
| mph | Miles per hour in meter per second. |
| mach | One Match in meter per second. |
Related Articles: