Added another run time error example.

This commit is contained in:
Eric V. Smith 2015-08-07 22:25:27 -04:00
parent 84c290c550
commit fe83f468f6
1 changed files with 13 additions and 2 deletions

View File

@ -276,8 +276,8 @@ Invalid expressions::
SyntaxError: invalid syntax SyntaxError: invalid syntax
Run time errors occur when evaluating the expressions inside an Run time errors occur when evaluating the expressions inside an
f-string. Note that an f-string can be executed multiple times, and f-string. Note that an f-string can be evaluated multiple times, and
work sometimes and raise an error other times:: work sometimes and raise an error at other times::
>>> d = {0:10, 1:20} >>> d = {0:10, 1:20}
>>> for i in range(3): >>> for i in range(3):
@ -289,6 +289,17 @@ work sometimes and raise an error other times::
File "<stdin>", line 2, in <module> File "<stdin>", line 2, in <module>
KeyError: 2 KeyError: 2
or::
>>> for x in (32, 100, 'fifty'):
... f'x = {x:+3}'
...
'x = +32'
'x = +100'
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ValueError: Sign not allowed in string format specifier
Leading whitespace in expressions is skipped Leading whitespace in expressions is skipped
-------------------------------------------- --------------------------------------------