Created
November 28, 2016 14:04
-
-
Save chendi0x7C00/85a9857b551754adc6ff0830122c52e7 to your computer and use it in GitHub Desktop.
repr is for developers, print is for software users
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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