From 108fb5d3dfc76c78d51126660ce891f9d1ee10eb Mon Sep 17 00:00:00 2001 From: Janine vN Date: Thu, 9 Sep 2021 10:31:48 -0400 Subject: Add string-formatting tag Adds a tag to show the string formatting mini language --- bot/resources/tags/string-formatting.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 bot/resources/tags/string-formatting.md diff --git a/bot/resources/tags/string-formatting.md b/bot/resources/tags/string-formatting.md new file mode 100644 index 000000000..fba5577b8 --- /dev/null +++ b/bot/resources/tags/string-formatting.md @@ -0,0 +1,27 @@ +**String Formatting Mini Language** +The String Formatting Language in Python is a powerful way to tailor the display of strings and other data structures. This string formatting mini language works for f-strings and .format(). + +Take a look at some of these examples! +```py +my_num = 2134234523 +print(f"{my_num:,}") + +my_smaller_num = -30.0532234 +print(f"{my_smaller_num:=09.2f}") + +my_str = "Center me!" +print(f"{my_str:^20}") + +repr_str = "Spam \t Ham" +print(f"{repr_str!r}") +``` +Results: +``` +2,134,234,523 +-00030.05 + Center me! +'Spam \t Ham' +``` +**Full Specification & Resources** +[String Formatting Mini Language Specification](https://docs.python.org/3/library/string.html#format-specification-mini-language) +[pyformat.info](https://pyformat.info/) \ No newline at end of file -- cgit v1.2.3 From 693a91ea12b6f856da6c3a2ad6e17bcf12779d53 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Thu, 9 Sep 2021 10:52:14 -0400 Subject: Add required newline to end of file --- bot/resources/tags/string-formatting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/resources/tags/string-formatting.md b/bot/resources/tags/string-formatting.md index fba5577b8..272b96af3 100644 --- a/bot/resources/tags/string-formatting.md +++ b/bot/resources/tags/string-formatting.md @@ -24,4 +24,4 @@ Results: ``` **Full Specification & Resources** [String Formatting Mini Language Specification](https://docs.python.org/3/library/string.html#format-specification-mini-language) -[pyformat.info](https://pyformat.info/) \ No newline at end of file +[pyformat.info](https://pyformat.info/) -- cgit v1.2.3 From 3d6ba16691512292c239e76c0a9ae373b3982bc2 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Thu, 9 Sep 2021 12:28:13 -0400 Subject: Change formatting of examples After some discussion back and forth, I've adjusted how to display the examples and code bock to be of a more REPL-style. Additionally, a filler character for the "Center Me!" string is added to illustrate how exactly in centers it. This commit also adds some small styling changes. --- bot/resources/tags/string-formatting.md | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/bot/resources/tags/string-formatting.md b/bot/resources/tags/string-formatting.md index 272b96af3..707d19c90 100644 --- a/bot/resources/tags/string-formatting.md +++ b/bot/resources/tags/string-formatting.md @@ -1,25 +1,22 @@ -**String Formatting Mini Language** -The String Formatting Language in Python is a powerful way to tailor the display of strings and other data structures. This string formatting mini language works for f-strings and .format(). +**String Formatting Mini-Language** +The String Formatting Language in Python is a powerful way to tailor the display of strings and other data structures. This string formatting mini language works for f-strings and `.format()`. Take a look at some of these examples! ```py -my_num = 2134234523 -print(f"{my_num:,}") +>>> my_num = 2134234523 +>>> print(f"{my_num:,}") +2,134,234,523 -my_smaller_num = -30.0532234 -print(f"{my_smaller_num:=09.2f}") +>>> my_smaller_num = -30.0532234 +>>> print(f"{my_smaller_num:=09.2f}") +-00030.05 -my_str = "Center me!" -print(f"{my_str:^20}") +>>> my_str = "Center me!" +>>> print(f"{my_str:-^20}") +-----Center me!----- -repr_str = "Spam \t Ham" -print(f"{repr_str!r}") -``` -Results: -``` -2,134,234,523 --00030.05 - Center me! +>>> repr_str = "Spam \t Ham" +>>> print(f"{repr_str!r}") 'Spam \t Ham' ``` **Full Specification & Resources** -- cgit v1.2.3