Skip to content

Commit 6a9cd29

Browse files
author
guozhen3
committed
Revert "Revert "repr""
This reverts commit 846d238.
1 parent 846d238 commit 6a9cd29

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ Out[5]: True
7272
调用对象的 \__repr__ 方法,获得该方法的返回值,如下例子返回值为字符串
7373

7474
```python
75-
In [1]: class Student():
76-
...: def __init__(self,id,name):
77-
...: self.id = id
78-
...: self.name = name
79-
...: def __repr__(self):
80-
...: return 'id = '+self.id +', name = '+self.name
81-
...:
82-
...:
75+
class Student():
76+
def __init__(self,id,name):
77+
self.id = id
78+
self.name = name
79+
def __repr__(self):
80+
return 'id = '+self.id +', name = '+self.name
81+
```
8382

84-
In [2]: xiaoming = Student(id='001',name='xiaoming')
83+
```python
84+
In [2]: xiaoming = Student(id='1',name='xiaoming')
8585

8686
In [3]: print(xiaoming)
87-
id = 001, name = xiaoming
87+
id = 1, name = xiaoming
8888

8989
In [4]: ascii(xiaoming)
9090
Out[4]: 'id = 001, name = xiaoming'

0 commit comments

Comments
 (0)