Add examples

This commit is contained in:
Victor Zverovich 2018-02-10 06:33:03 -08:00
parent 6cb68f9496
commit 66b25ef0d0

View File

@ -336,6 +336,16 @@ Aligning the text and specifying a width::
format("{:*^30}", "centered"); // use '*' as a fill char format("{:*^30}", "centered"); // use '*' as a fill char
// Result: "***********centered***********" // Result: "***********centered***********"
Dynamic width::
format("{:<{}}", "left aligned", 30);
// Result: "left aligned "
Dynamic precision::
format("{:.{}f}", 3.14, 1);
// Result: "3.1"
Replacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign:: Replacing ``%+f``, ``%-f``, and ``% f`` and specifying a sign::
format("{:+f}; {:+f}", 3.14, -3.14); // show it always format("{:+f}; {:+f}", 3.14, -3.14); // show it always
@ -360,13 +370,6 @@ Replacing ``%x`` and ``%o`` and converting the value to different bases::
format("{:,}", 1234567890); format("{:,}", 1234567890);
'1,234,567,890' '1,234,567,890'
Expressing a percentage::
>>> points = 19
>>> total = 22
Format("Correct answers: {:.2%}") << points/total)
'Correct answers: 86.36%'
Using type-specific formatting:: Using type-specific formatting::
>>> import datetime >>> import datetime