@@ -112,13 +112,10 @@ the message is 'hello'
112
112
113
113
Combining ` repr() ` with [ string
114
114
formatting] ( ../basics/handy-stuff-strings.md#string-formatting ) is also
115
- easy. ` % ` formatting has a ` %r ` formatter, and ` .format() ` formatting
116
- has a ` !r ` flag.
115
+ easy.
117
116
118
117
``` python
119
- >> > print (" the message is %r " % (message,))
120
- the message is ' hello'
121
- >> > print (" the message is {!r } " .format(message))
118
+ >> > print (f " the message is { repr (message)} " )
122
119
the message is ' hello'
123
120
>> >
124
121
```
@@ -155,8 +152,7 @@ follow one of these styles:
155
152
... self .name = name
156
153
... self .founding_year = founding_year
157
154
... def __repr__ (self ):
158
- ... return ' Website(name=%r , founding_year=%r )' % (
159
- ... self .name, self .founding_year)
155
+ ... return f ' Website(name= { repr (self .name)} , founding_year= { repr (self .founding_year)} ) '
160
156
...
161
157
>> > github = Website(' GitHub' , 2008 )
162
158
>> > github
@@ -174,8 +170,7 @@ follow one of these styles:
174
170
... self .name = name
175
171
... self .founding_year = founding_year
176
172
... def __repr__ (self ):
177
- ... return ' <Website %r , founded in %r >' % (
178
- ... self .name, self .founding_year)
173
+ ... return f ' <Website { repr (self .name)} , founded in { repr (self .founding_year)} > '
179
174
...
180
175
>> > github = Website(' GitHub' , 2008 )
181
176
>> > github
0 commit comments