How do I use a not in the new match/case structure?
a = 5
match a:
case not 10:
print(a)
This produces an error. How would I correctly syntax this?
>Solution :
I don’t think you can use not in structural pattern matching, an alternative is to capture the values you need and then use the default _ case to be the ‘not’ expression.
a = 5
match a:
case 10:
print(a)
case _:
print("not 10")
EDIT:
I was curious and did some research, turns out this was rejected confirming it is not possible!
https://www.python.org/dev/peps/pep-0622/#negative-match-patterns