Selected Reading

SciPy - unit() Method



The SciPy unit() Method is used to access the specific unit from the physical constant using the dictionary. This method contains values and unit. It is defined under the module scipy.constants. The primarily use of this function allows user to calculate the accurate scientific calculation.

Syntax

Following is the syntax of the SciPy unit() Method −

unit(key)

Parameters

This method accepts only a single parameter −

  • key: This parameter is prefer as a string which specify the name of physical constant.

Return value

This method reruns an integer value.

Example 1

Following is the basic SciPy unit() Method that illustrate the usage of physical constant("speed of light in vacuum").

from scipy.constants import physical_constants

key = 'speed of light in vacuum'
unit = physical_constants[key][2]

print(f"The unit of {key} is {unit}.")

Output

The above code produces the following result −

The unit of speed of light in vacuum is 0.0.

Example 2

Here, we use the key of physical constant as "Planck constant" that helps to display the result in unit form.

from scipy.constants import physical_constants

key = 'Planck constant'
unit = physical_constants[key][0]

print(f"The unit of {key} is {unit}.")

Output

The above code produces the following result −

The unit of Planck constant is 6.62607015e-34.
scipy_reference.htm
Advertisements