Force

class Force(value: float | int, unit: str)

Bases: UnitBase

Force object.

Attributes

unitstr

Symbol of the unit of measurement for force.

valuefloat or int

Force numerical value.

Methods

to()

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

to(target_unit: str, inplace: bool = False) Force

It converts actual value to a new value computed using target_unit as the reference unit of measurement.

If inplace is True, it overrides actual value and unit, otherwise it returns a new instance with the converted value and the target_unit as unit.

Parameters

target_unitstr

Target unit to which convert the current value.

inplacebool, optional

Whether to override the current instance value. Default is False, so it does not override the current value.

Returns

Force

Converted force.

Raises

TypeError
  • If target_unit is not a str,

  • if inplace is not a bool.

KeyError

If the target_unit is not among available ones.

Examples

Force instantiation.

>>> from gearpy.units import Force
>>> f = Force(1, 'N')
>>> f
... 1 N

Conversion from newton to kilogram force with inplace = False by default, so it does not override the current value.

>>> f.to('kgf')
... 0.10197162129779283 kgf
>>> f
... 1 N

Conversion from newton to kilogram force with inplace = True, in order to override the current value.

>>> f.to('kgf', inplace = True)
... 0.10197162129779283 kgf
>>> f
... 0.10197162129779283 kgf
property unit: str

Symbol of the unit of measurement for force. It must be a str. Available units are:

  • 'N' for newton,

  • 'mN' for milli-newton,

  • 'kN' for kilo-newton,

  • 'kgf' for kilogram force,

  • 'gf' for gram force.

Returns

str

Symbol of the unit of measurement for force.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Force numerical value. The relative unit is expressed by the unit property.

Returns

float or int

Force numerical value.

Raises

TypeError

If value is not a float or an int.