Surface

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

Bases: UnitBase

Surface object.

Attributes

unitstr

Symbol of the unit of measurement for surface.

valuefloat or int

Surface 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) Surface

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

Surface

Converted surface.

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

Surface instantiation.

>>> from gearpy.units import Surface
>>> s = Surface(1, 'm^2')
>>> s
... 1 m^2

Conversion from square meter to square millimeter with inplace = False by default, so it does not override the current value.

>>> s.to('mm^2')
... 1000000.0 mm^2
>>> s
... 1 m^2

Conversion from square meter to square millimeter with inplace = True, in order to override the current value.

>>> s.to('mm^2', inplace = True)
... 1000000.0 mm^2
>>> s
... 1000000.0 mm^2
property unit: str

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

  • 'm^2' for square meter,

  • 'dm^2' for square decimeter,

  • 'cm^2' for square centimeter,

  • 'mm^2' for square millimeter.

Returns

str

Symbol of the unit of measurement for surface.

Raises

TypeError

If unit is not a str.

KeyError

If the unit is not among available ones.

property value: float | int

Surface numerical value. The relative unit is expressed by the unit property. It must be positive.

Returns

float or int

Surface numerical value.

Raises

TypeError

If value is not a float or an int.

ValueError

If value is negative or null.