From 638222fac9cc30bea8fa964193972d38fdc9dc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Zaczy=C5=84ski?= Date: Wed, 27 Nov 2024 14:41:24 +0100 Subject: [PATCH 1/2] Fix a broken link and title --- python-f-string/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python-f-string/README.md b/python-f-string/README.md index 6b2bfa0c4c..d014672494 100644 --- a/python-f-string/README.md +++ b/python-f-string/README.md @@ -1,3 +1,3 @@ -# Python's F-String: An Improved String Interpolation and Formatting Tool +# Python's F-String for String Interpolation and Formatting -This folder provides the code examples for the Real Python tutorial [Python's F-String: An Improved String Interpolation and Formatting Tool](https://realpython.com/python-f-string/). \ No newline at end of file +This folder provides the code examples for the Real Python tutorial [Python's F-String for String Interpolation and Formatting](https://realpython.com/python-f-strings/). From bd032b21393ad6a6a655c22c40941a30b34874a3 Mon Sep 17 00:00:00 2001 From: Geir Arne Hjelle Date: Thu, 28 Nov 2024 16:32:00 +0100 Subject: [PATCH 2/2] Final QA (#616) --- name-main-idiom/echo.py | 6 ++---- name-main-idiom/echo_args.py | 6 ++---- name-main-idiom/echo_demo.py | 6 ++---- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/name-main-idiom/echo.py b/name-main-idiom/echo.py index 5b7b5d2d3c..940b7664b6 100644 --- a/name-main-idiom/echo.py +++ b/name-main-idiom/echo.py @@ -1,9 +1,7 @@ def echo(text: str, repetitions: int = 3) -> str: """Imitate a real-world echo.""" - echoed_text = "" - for i in range(repetitions, 0, -1): - echoed_text += f"{text[-i:]}\n" - return f"{echoed_text.lower()}." + echoes = [text[-i:].lower() for i in range(repetitions, 0, -1)] + return "\n".join(echoes + ["."]) if __name__ == "__main__": diff --git a/name-main-idiom/echo_args.py b/name-main-idiom/echo_args.py index b33a75f23e..4cad04ff4b 100644 --- a/name-main-idiom/echo_args.py +++ b/name-main-idiom/echo_args.py @@ -3,10 +3,8 @@ def echo(text: str, repetitions: int = 3) -> str: """Imitate a real-world echo.""" - echoed_text = "" - for i in range(repetitions, 0, -1): - echoed_text += f"{text[-i:]}\n" - return f"{echoed_text.lower()}." + echoes = [text[-i:].lower() for i in range(repetitions, 0, -1)] + return "\n".join(echoes + ["."]) def main() -> None: diff --git a/name-main-idiom/echo_demo.py b/name-main-idiom/echo_demo.py index 5e9f5bd9fa..fb7ff89fff 100644 --- a/name-main-idiom/echo_demo.py +++ b/name-main-idiom/echo_demo.py @@ -1,9 +1,7 @@ def echo(text: str, repetitions: int = 3) -> str: """Imitate a real-world echo.""" - echoed_text = "" - for i in range(repetitions, 0, -1): - echoed_text += f"{text[-i:]}\n" - return f"{echoed_text.lower()}." + echoes = [text[-i:].lower() for i in range(repetitions, 0, -1)] + return "\n".join(echoes + ["."]) if __name__ == "__main__":