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.
|
||||
1st way (you'll most probably want to use this) You can just check for all the criteria inside your function by using
2nd way (only for debugging) You can use
So this will check if both criteria are met, otherwise an |
|||||||||
|
list
s? Wouldn't other sequences be acceptable? And why exactly two elements? What do they represent? Why do you want them in alist
as opposed to being passed as two separate arguments? – Blacklight Shining 1 hour ago