Who in Python has to check if the correct type of the arguments is passed to a function or method:
The programmer calling the function must ensure that the type of the argument passed is correct. The function does not explicitly check the argument passed in the first stages, but simply uses it as if it were a reliably correct type. In the course of operation, functions can themselves be generated or explicitly generated various exceptions that will indicate the wrong argument. This exception will be described in docstring
The function explicitly checks the type of the passed argument at the first stage and throws an exception if something is wrong, for example, TypeError.
- Something else
?
For example, if we pass to an function (for example) not an iterable, but an integer or a real number, then a TypeError exception is thrown (since int and float are not iterable). But at the very beginning, you can explicitly check yourself, for example, that the argument passed is an iterable object and generate something.
def is_positive_or_zero_values ββ(iterable):
"" "Check whether all elements in iterable have numbers equal to or greater than zero.
Args:
iterable: an iterable object containing values ββto check.
Returns:
bool: True, if all elements in iterable have numbers that are equal to or greater than zero ..
False, otherwise.
"" "
if iterable:
if is_numbers (iterable):
return all (map (lambda x: x> = 0, iterable))
else:
return false
else:
return false