Skip to content

Instantly share code, notes, and snippets.

@ycui1
Created October 5, 2021 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ycui1/e7503437303dfe473c48b4900ddd5c70 to your computer and use it in GitHub Desktop.
Save ycui1/e7503437303dfe473c48b4900ddd5c70 to your computer and use it in GitHub Desktop.
>>> 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