neclib.core.data_type.value_range#
Aliases#
None |
- class ValueRange(lower, upper, strict=False)[source]#
Bases:
Generic
[T
]Value range bound by 2 values.
- Parameters:
lower (T) – Lower bound of the range. Any type with comparison support is allowed.
upper (T) – Upper bound of the range. Any type with comparison support is allowed.
strict (bool) – If
True
, the value exactly equals to the bound will judged to be not in the range.
Examples
>>> valid_value = neclib.ValueRange(0, 1) >>> 0.5 in valid_value True >>> -1 in valid_value False
You can also check lexical order of strings:
>>> valid_str = neclib.ValueRange("aaa", "bbb") >>> "abc" in valid_str True
The lower and upper bounds can be iterated over:
>>> _ = [print(limits) for limits in valid_value] aaa bbb
- property width: Optional[T]#
Width of the range.
Examples
>>> valid_value = neclib.ValueRange(0, 1) >>> valid_value.width 1
- contain_all(values)[source]#
Check if all values are in the range.
- Parameters:
values (Iterable[Any]) – Iterable object to be checked.
- Return type:
bool
Examples
>>> valid_value = neclib.ValueRange(0, 1) >>> valid_value.contain_all([0.5, 1.6]) False
- contain_any(values)[source]#
Check if any value is in the range.
- Parameters:
values (Iterable[Any]) – Iterable object to be checked.
- Return type:
bool
Examples
>>> valid_value = neclib.ValueRange(0, 1) >>> valid_value.contain_any([0.5, 1.6]) True