Skip to content

Instantly share code, notes, and snippets.

@tao4yu
Last active September 28, 2016 09:18
Show Gist options
  • Save tao4yu/e4737e51be44e6f983c030fc1ede18f5 to your computer and use it in GitHub Desktop.
Save tao4yu/e4737e51be44e6f983c030fc1ede18f5 to your computer and use it in GitHub Desktop.
# ! /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)
@tao4yu
Copy link
Author

tao4yu commented Sep 28, 2016

In[1]: p = Pair(3, 4)
In[2]: print ('p is {0!r}'.format(p))
p is Pair(3, 4)

@tao4yu
Copy link
Author

tao4yu commented Sep 28, 2016

或者这样实现

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