Skip to content

Instantly share code, notes, and snippets.

@chendi0x7C00
Created November 28, 2016 14:04
Show Gist options
  • Save chendi0x7C00/85a9857b551754adc6ff0830122c52e7 to your computer and use it in GitHub Desktop.
Save chendi0x7C00/85a9857b551754adc6ff0830122c52e7 to your computer and use it in GitHub Desktop.
repr is for developers, print is for software users
# coding=UTF-8
class Engineer(object):
def __init__(self, name, specialty):
self.name = name
self.specialty = specialty
def __repr__(self):
# __repr__ is for developers
# repr()
# evaluated in REPL
return "Engineer({self.name}, {self.specialty})".format(self=self)
def __str__(self):
# __str__ is for endusers
# str()
# print()
return "Engineer, name: {self.name}, specialty: {self.specialty}".format(self=self)
engineer = Engineer("ChenDi", "BackEnd");
print(engineer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment