Skip to content

Instantly share code, notes, and snippets.

@anilpai
Created December 22, 2017 19:03
Show Gist options
  • Save anilpai/b3cc383e9957fe7f6c23c4cf4b31a440 to your computer and use it in GitHub Desktop.
Save anilpai/b3cc383e9957fe7f6c23c4cf4b31a440 to your computer and use it in GitHub Desktop.
class Student:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
@classmethod
def from_string(cls, name_str):
first_name, last_name = map(str, name_str.split(' '))
student = cls(first_name, last_name)
return student
@classmethod
def from_json(cls, name_str):
# parse the json
return name_str
@staticmethod
def is_full_name(name_str):
names = name_str.split(" ")
return len(names) > 1
if __name__=='__main__':
stud = Student('Anil', 'Pai')
print(stud.first_name, stud.last_name)
stud = Student.from_string('Anil Pai')
print(stud.first_name, stud.last_name)
flag = Student.is_full_name('Anil Pai')
print(flag)
flag = Student.is_full_name('Anil')
print(flag)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment