用于访问 scipy.constants() 模块中的常量数据库的各种内置方法是什么?
很难记住所有物理常数的值、单位和精度。这就是为什么有四种方法可以帮助我们访问物理常量。让我们通过示例来理解这些方法-scipy.constants()
scipy。constants.value(key)-这种方法会给我们以键索引的物理常数的值。
参数
key-它代表字典physical_constants中的键。它的值是Python字符串或Unicode。
退货
value-它表示物理常量中与关键参数对应的值。它的值是浮点型。
示例
from scipy import constants constants.value(u'proton mass')输出结果
1.67262192369e-27
scipy。constants.unit(key)-这种方法将为我们提供由键索引的物理常数的单位。
参数
key-它代表字典physical_constants中的键。它的值是Python字符串或Unicode。
退货
unit-表示物理常数中关键参数对应的单位。它的值是一个Python字符串。
示例
from scipy import constants constants.value(u'elementary charge')输出结果
‘C’
scipy。constants.precision(key)-这种方法将为我们提供由键索引的物理常数的相对精度。
参数
key-它代表字典physical_constants中的键。它的值是Python字符串或Unicode。
退货
prec-它表示与关键参数对应的physical_constants中的相对精度。它的值是浮点型。
示例
from scipy import constants constants.value(u'proton mass')输出结果
3.0491050773439597e-10
scipy.constants.find(sub=None,disp=False)-此方法将为我们提供具有给定字符串的physical_constants键的列表。
参数
sub-它表示要搜索键的子字符串。默认情况下,它将返回所有键。
disp-它是布尔类型。如果为True,它将打印键并返回无。如果为false,它将只返回键列表而不打印任何内容。
退货
键-它代表键列表。如果disp为FALSE,它将返回键列表。如果disp为TRUE,它将不会返回任何内容。
示例
#Importing the modules
fromscipy.constantsimport 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)
