Let's assume I have the following function:
def sum_ints(my_list: list[int]) -> int:
return sum(my_list)
Before I start adding the elements in my_list
, I want to check the type of all elements using the new match
statement.
If my_list
has a length of 2 for example, I can do:
def sum_ints(my_list: list[int]) -> int:
match my_list:
case [int(), int()]:
return sum(my_list)
case _:
raise Exception("...")
How can I match the case for a list with n
elements?