SciPy.constants() 模块中有哪些访问常数数据库的内置方法?


记住所有物理常数的值、单位和精度是很困难的。这就是 scipy.constants() 使用四种方法帮助我们访问物理常数的原因。让我们一起了解这些方法以及示例:

  • scipy.constants.value(key)− 此方法将给出由键索引的物理常数的值。

参数

  • key- 它代表物理常数字典中的键。其值为 Python 字符串或 Unicode。

返回值

  • value- 它代表与键参数对应的物理常数的值。其值为浮点型。

示例

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

输出

1.67262192369e-27
  • scipy.constants.unit(key)− 此方法将给出由键索引的物理常数的单位。

参数

  • key- 它代表物理常数字典中的键。其值为 Python 字符串或 Unicode。

返回值

  • unit- 它代表与键参数对应的物理常数的单位。其值为 Python 字符串。

示例

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

输出

‘C’
  • scipy.constants.precision(key)− 此方法将给出由键索引的物理常数的相对精度。

参数

  • key- 它代表物理常数字典中的键。其值为 Python 字符串或 Unicode。

返回值

  • prec- 它代表与键参数对应的物理常数的相对精度。其值为浮点型。

示例

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

输出

3.0491050773439597e-10
  • scipy.constants.find(sub=None, disp=False)− 此方法将给出具有给定字符串的物理常数键的列表。

参数

  • sub- 它代表要搜索键的子字符串。默认情况下,它将返回所有键。

  • disp- 它为布尔类型。如果为 True,它将打印键并返回 None。如果为 False,它将只返回键的列表,而不打印任何内容。

返回值

  • keys- 它代表键的列表。如果 disp 为 FALSE,它将返回键的列表。如果 disp 为 TRUE,它将不返回任何内容。

示例

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

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

输出

['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']

示例

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

输出

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

更新于:2021年11月24日

166 次浏览

开启您的职业生涯

完成课程获得认证

开始学习
广告
© . All rights reserved.