SciPy Constants

SciPy Tutorial

 SciPy Constants (Complete Explanation)

SciPy Constants are a collection of predefined scientific and mathematical constants provided by the module:

 
scipy.constants

These constants are accurate, standardized, and ready to use, so you don’t have to memorize or manually define values like the speed of light, Planck’s constant, or gravitational constant.


 Why Use SciPy Constants?

Using It helps because:

  •  Values are highly accurate


  •  Based on international standards (SI units)


  •  Saves time & avoids calculation mistakes


  •  Widely used in physics, chemistry, engineering



 Importing SciPy Constants

 
from scipy import constants

Or import specific constants:

 
from scipy.constants import c, pi

 Commonly Used Scientific Constants

 Mathematical Constants

 
from scipy import constants

print(constants.pi) # π
print(constants.e) # Euler's number

 


 Physical Constants

Constant Meaning
c Speed of light (m/s)
G Gravitational constant
h Planck constant
k Boltzmann constant
N_A Avogadro number
R Gas constant
g Acceleration due to gravity

Example:

 
from scipy import constants

print("Speed of light:", constants.c)
print("Gravitational constant:", constants.G)
print("Planck constant:", constants.h)

 


 Unit-Based Constants

SciPy also provides unit conversions.

 Length

 
from scipy import constants

print(constants.inch) # inch in meters
print(constants.foot)
print(constants.mile)

 


 Mass

 
print(constants.pound) # pound in kg
print(constants.atomic_mass)

 Time

 
print(constants.minute)
print(constants.hour)
print(constants.day)

 Temperature

 
print(constants.zero_Celsius) # 0°C in Kelvin

 Constants with Units Information

You can access detailed info using physical_constants:

 
from scipy.constants import physical_constants

value, unit, uncertainty = physical_constants["speed of light in vacuum"]
print(value)
print(unit)
print(uncertainty)

 

  •  Very useful for research & academic work.

 Angle Conversions

 
from scipy import constants

print(constants.degree) # degree in radians
print(constants.arcmin)
print(constants.arcsec)

 


 Energy Constants

 
print(constants.electron_volt)
print(constants.calorie)
print(constants.kilo)

 Example: Practical Use Case

Calculate Energy using Einstein’s Equation

Calculate Energy using Einstein’s Equation

 
from scipy import constants

m = 1 # mass in kg
E = m * constants.c**2
print(E)

 


 Why Not Use Manual Values?

  •  Hard-coded values may be inaccurate
  •  Units can be inconsistent
  •  Difficult to maintain

 They are trusted & standardized


 Summary

  • scipy.constants provides scientific & mathematical constants
  •  Covers physics, chemistry, math & engineering
  •  Includes unit conversions
  •  Ensures accuracy and reliability
  •  Essential for scientific computing

You may also like...