Last active
September 28, 2016 09:18
-
-
Save tao4yu/e4737e51be44e6f983c030fc1ede18f5 to your computer and use it in GitHub Desktop.
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
# ! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
class Pair: | |
def __init__(self, x, y): | |
self.x = x | |
self.y = y | |
def __repr__(self): | |
return 'Pair({0.x!r}, {0.y!r})'.format(self) | |
def __str__(self): | |
return '({0.x!s}, {0.y!s})'.format(self) |
或者这样实现
def repr(self):
return 'Pair (%r, %r)' % (self.x, self.y)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In[1]: p = Pair(3, 4)
In[2]: print ('p is {0!r}'.format(p))
p is Pair(3, 4)