From 66b25ef0d019d164996ac79f698ecb7c88e3bce0 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 10 Feb 2018 06:33:03 -0800 Subject: [PATCH] Add examples --- doc/syntax.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/doc/syntax.rst b/doc/syntax.rst index 2d994c0a..0cce0bf5 100644 --- a/doc/syntax.rst +++ b/doc/syntax.rst @@ -336,6 +336,16 @@ Aligning the text and specifying a width:: format("{:*^30}", "centered"); // use '*' as a fill char // 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:: 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); '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:: >>> import datetime