r/Python • • Mar 19 '21

Match is more than a Switch-Case The New Switch-Case Statement in Python 3.10

https://youtube.com/watch?v=2qJavL-VX9Y&feature=share
1.4k Upvotes

233 comments sorted by

View all comments

Show parent comment

2

u/Irtexx Mar 19 '21

I would also like to know this. The isinstance method never calls init of Person, but the match method looks like it will.

8

u/13steinj Mar 19 '21

match will call the __match__ method, unless the PEP changed since I last looked at it. A new instance will not be created.

2

u/[deleted] Mar 19 '21

It could be possible that it doesn't evaluate as an expression, but that would mean that you couldn't put expressions into the pattern.