Created
October 5, 2021 16:00
-
-
Save ycui1/e7503437303dfe473c48b4900ddd5c70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> class Student: | |
... def __init__(self, name): | |
... self.name = name | |
... | |
... | |
>>> class Teacher: | |
... def __init__(self, name): | |
... self.name = name | |
... | |
... | |
>>> def spm_school(person): | |
... match person: | |
... case Student(name=name): | |
... print("Student:", name) | |
... case Teacher(name=name): | |
... print("Teacher:", name) | |
... case _: | |
... print("Hello, person") | |
... | |
... | |
>>> spm_school(Student("John")) | |
Student: John | |
>>> spm_school(Teacher("Jeff")) | |
Teacher: Jeff | |
>>> spm_school("random") | |
Hello, person | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment