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.