File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -239,8 +239,9 @@ But that gets complicated if you have many things to add.
239
239
Instead it's recommended to use string formatting. It means putting
240
240
other things in the middle of a string.
241
241
242
- Python has two ways to format strings. One is not better than the other,
243
- they are just different. The two ways are:
242
+ Python has multiple ways to format strings. One is not necessarily
243
+ better than others, they are just different. Here's a few ways to solve
244
+ our problem:
244
245
245
246
- ` .format() ` -formatting, also known as new-style formatting. This
246
247
formatting style has a lot of features, but it's a little bit more
@@ -271,7 +272,17 @@ they are just different. The two ways are:
271
272
>> >
272
273
```
273
274
274
- Both formatting styles have many other features also:
275
+ - f- strings are even less typing, but new in Python 3.6 . ** Use this only if
276
+ you know that nobody will need to run your code on Python versions older
277
+ than 3.6 .** Here the f is short for " format" .
278
+
279
+ ```py
280
+ >> > f " My name is { name} and I'm on the { channel} channel on { network} . "
281
+ " My name is Akuli and I'm on the ##learnpython channel on freenode."
282
+ >> >
283
+ ```
284
+
285
+ All of these formatting styles have many other features also:
275
286
276
287
```py
277
288
>> > ' Three zeros and number one: {:04d } ' .format(1 )
You can’t perform that action at this time.
0 commit comments