| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 1c4dcaf commit f5bd99b
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -172,7 +172,7 @@ Positional and keyword arguments can be arbitrarily combined:: | |||
| 172 | 172 | If you have a really long format string that you don't want to split up, it | |
| 173 | 173 | would be nice if you could reference the variables to be formatted by name | |
| 174 | 174 | instead of by position. This can be done by simply passing the dict and using | |
| 175 | - square brackets ``'[]'`` to access the keys :: | ||
| 175 | + square brackets ``'[]'`` to access the keys. :: | ||
| 176 | 176 | ||
| 177 | 177 | >>> table = {'Sjoerd': 4127, 'Jack': 4098, 'Dcab': 8637678} | |
| 178 | 178 | >>> print('Jack: {0[Jack]:d}; Sjoerd: {0[Sjoerd]:d}; ' | |
@@ -257,10 +257,10 @@ left with zeros. It understands about plus and minus signs:: | |||
| 257 | 257 | Old string formatting | |
| 258 | 258 | --------------------- | |
| 259 | 259 | ||
| 260 | - The ``%`` operator can also be used for string formatting. It interprets the | ||
| 261 | - left argument much like a :c:func:`sprintf`\ -style format string to be applied | ||
| 262 | - to the right argument, and returns the string resulting from this formatting | ||
| 263 | - operation. For example:: | ||
| 260 | + The % operator (modulo) can also be used for string formatting. Given ``'string' | ||
| 261 | + % values``, instances of ``%`` in ``string`` are replaced with zero or more | ||
| 262 | + elements of ``values``. This operation is commonly known as string | ||
| 263 | + interpolation. For example:: | ||
| 264 | 264 | ||
| 265 | 265 | >>> import math | |
| 266 | 266 | >>> print('The value of pi is approximately %5.3f.' % math.pi) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments