How can I limit python function parameter to accept only arrays of some fixed-size?
I tried this but it doesn't compile:
def func(a : array[2]):
with
TypeError: 'module' object is not subscriptable
I'm new to this language.
What about checking the length inside of the function? Here I just raised an error, but you could do anything.
def func(array):
if len(array) != 2:
raise ValueError("array with length 2 was expected")
# code here runs if len(array) == 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With