What are various inbuilt methods used to access constants database in scipy.constants() module?


It is difficult to remember the values, units, and precisions of all physical constants. That’s the reason scipy.constants() have four methods with the help of which we can access physical constants. Let’s understand these methods along with examples −

  • scipy.constants.value(key)− This method will give us the value in physical constants indexed by key.

Parameters

  • key- It represents the key in dictionary physical_constants. Its value is a Python string or Unicode.

Returns

  • value- It represents the value in physical_constants corresponding to the key parameter. Its value is of float type.

Example

from scipy import constants
constants.value(u'proton mass')

Output

1.67262192369e-27
  • scipy.constants.unit(key)− This method will give us the unit in physical constants indexed by key.

Parameters

  • key- It represents the key in dictionary physical_constants. Its value is a Python string or Unicode.

Returns

  • unit- It represents the unit in physical_constants corresponding to the key parameter. Its value is a Python string.

Example

from scipy import constants
constants.value(u'elementary charge')

Output

‘C’
  • scipy.constants.precision(key)− This method will give us the relative precision in physical constants indexed by key.

Parameters

  • key- It represents the key in dictionary physical_constants. Its value is a Python string or Unicode.

Returns

  • prec- It represents the relative precision in physical_constants corresponding to the key parameter. Its value is of float type.

Example

from scipy import constants
constants.value(u'proton mass')

Output

3.0491050773439597e-10
  • scipy.constants.find(sub=None, disp=False)− This method will give us the list of physical_constants keys having a given string.

Parameters

  • sub- It represents substring to search keys for. By default, it will return all the keys.

  • disp- It is of Boolean type. If True, it will print the keys and return none. If false, it will only return the list of keys without printing anything.

Returns

  • keys- It represents the list of keys. It will return the list of keys if disp is FALSE. It will not return anything if disp is TRUE.

Example

#Importing the modules
from scipy.constants import find, physical_constants

#Finding constant with ‘Bohr’ in the key
find('Bohr')

Output

['Bohr magneton',
'Bohr magneton in Hz/T',
'Bohr magneton in K/T',
'Bohr magneton in eV/T',
'Bohr magneton in inverse meter per tesla',
'Bohr radius',
'deuteron mag. mom. to Bohr magneton ratio',
'electron mag. mom. to Bohr magneton ratio',
'helion mag. mom. to Bohr magneton ratio',
'muon mag. mom. to Bohr magneton ratio',
'neutron mag. mom. to Bohr magneton ratio',
'proton mag. mom. to Bohr magneton ratio',
'shielded helion mag. mom. to Bohr magneton ratio',
'shielded proton mag. mom. to Bohr magneton ratio',
'triton mag. mom. to Bohr magneton ratio']

Example

#Getting the constant called ‘Bohr radius’
physical_constants['Bohr radius']

Output

(5.29177210903e-11, 'm', 8e-21)

Updated on: 24-Nov-2021

120 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements