Skip to content

Commit f7823ac

Browse files
committed
added format string statement
1 parent 36ae4c0 commit f7823ac

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,27 @@
1818

1919
* Avoid using reserved keywords like `id` in variable names.
2020

21+
* Prefer inline format strings for readability whenever possible.
22+
23+
### Prefer NOT to do this:
24+
25+
```python
26+
theword = 'out'
27+
fstring_a = 'Who let %d dogs %s?' % (100, theword)
28+
fstring_b = 'Who let {:d} dogs {:s}?' % (100, theword)
29+
```
30+
31+
### Prefer the inline style:
32+
33+
```python
34+
theword = 'out'
35+
fstring_a = f'Who let {100:d} dogs {theword:s}?'
36+
# Sometimes, this style is necessary:
37+
base_string = f'Who let {:d} dogs {:s}?'
38+
...
39+
parsed_string = base_string.format(100, theword)
40+
```
41+
2142
* Don't use `map` or `filter`, use list comprehension for readability and clarity:
2243

2344
### DO NOT DO THIS:

0 commit comments

Comments
 (0)