Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created May 19, 2020 15:34
Show Gist options
  • Save ZhouYang1993/f5512950de50564c13bdf48eb4bef1fb to your computer and use it in GitHub Desktop.
Save ZhouYang1993/f5512950de50564c13bdf48eb4bef1fb to your computer and use it in GitHub Desktop.
Class Method and Static Method in Python
class Student:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
self.nickname = None
def set_nickname(self, name):
self.nickname = name
@classmethod
def get_from_string(cls, name_string: str):
first_name, last_name = name_string.split()
return Student(first_name, last_name)
@classmethod
def get_from_json(cls, json_obj):
pass
# return student
@classmethod
def get_from_excle(cls, excle_file):
pass
# return student
@classmethod
def get_from_audio_record(cls,audio):
pass
# return student
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment