Commit f3618970 authored by Mariatta's avatar Mariatta Committed by GitHub

Improve f-strings documentation (GH-3604)

Provide additional examples of using format specifiers in f-strings
Added examples for using integer and date format specifiers.
parent 0ec8c4bd
...@@ -676,6 +676,12 @@ Some examples of formatted string literals:: ...@@ -676,6 +676,12 @@ Some examples of formatted string literals::
>>> value = decimal.Decimal("12.34567") >>> value = decimal.Decimal("12.34567")
>>> f"result: {value:{width}.{precision}}" # nested fields >>> f"result: {value:{width}.{precision}}" # nested fields
'result: 12.35' 'result: 12.35'
>>> today = datetime(year=2017, month=1, day=27)
>>> f"{today:%b %d, %Y}" # using date format specifier
'January 27, 2017'
>>> number = 1024
>>> f"{number:#0x}" # using integer presentation type as format specifier
'0x400'
A consequence of sharing the same syntax as regular string literals is A consequence of sharing the same syntax as regular string literals is
that characters in the replacement fields must not conflict with the that characters in the replacement fields must not conflict with the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment