From 026f21e0201763125f7c61a72ccdc3531057d3a1 Mon Sep 17 00:00:00 2001 From: baniasbaabe Date: Sun, 21 Jan 2024 13:26:33 +0100 Subject: [PATCH] Add print end --- book/pythontricks/Chapter.ipynb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/book/pythontricks/Chapter.ipynb b/book/pythontricks/Chapter.ipynb index f8525a9..60670ff 100644 --- a/book/pythontricks/Chapter.ipynb +++ b/book/pythontricks/Chapter.ipynb @@ -920,6 +920,36 @@ "point = Point(2,4)\n", "point.z = 5 # Throws an error" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Modify Print Statements" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "When printing multiple elements in Python, it starts a new line by default.\n", + "\n", + "But, you can change this default to whatever you like by setting the `end` parameter in `print()`.\n", + "\n", + "See below where we change the `end` parameter to space." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sports = [\"football\", \"basketball\", \"volleyball\", \"tennis\", \"handball\"]\n", + "\n", + "for sport in sports:\n", + " print(sport, end=\" \")" + ] } ], "metadata": {