Skip to content

Instantly share code, notes, and snippets.

@pydong
Created December 23, 2013 00:08
Show Gist options
  • Select an option

  • Save pydong/8089956 to your computer and use it in GitHub Desktop.

Select an option

Save pydong/8089956 to your computer and use it in GitHub Desktop.
class Person(object):
def __init__(self,fname='', lname=''):
self.fname = fname
self.lname = lname
def __repr__(self):
return 'repr: '+ self.fname + ' ' + self.lname
def __str__(self):
return 'str: ' + self.fname + ' ' + self.lname
class Student(Person):
def __init__(self, fname='', lname='', id=''):
super(Student, self).__init__(fname, lname)
self.id = id
def __repr__(self):
return 'repr: ' + self.fname + ' ' + self.lname + ' ' + self.id
def __str__(self):
return 'str: ' + self.fname + ' ' + self.lname + ' ' + self.id
if __name__ == '__main__':
p = Person('Mike', 'Dong')
print p
print str(p)
s= Student('Mike', 'Dong', 'A001')
print s
print str(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment