24 lines
356 B
Python
24 lines
356 B
Python
#!/usr/bin/env python
|
|
# -*- encoding: utf-8 -*-
|
|
"""
|
|
Topic: 实例的字符串显示
|
|
Desc :
|
|
"""
|
|
|
|
|
|
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)
|
|
|
|
p = Pair(3, 4)
|
|
print(p)
|
|
|
|
|