{"id":110,"date":"2024-09-04T18:12:21","date_gmt":"2024-09-04T18:12:21","guid":{"rendered":"https:\/\/www.zframez.com\/articles\/?p=110"},"modified":"2024-10-16T15:49:17","modified_gmt":"2024-10-16T15:49:17","slug":"chapter-4-mastering-the-print-function-in-python","status":"publish","type":"post","link":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python","title":{"rendered":"Chapter 4: Mastering the Print Function in Python"},"content":{"rendered":"<body>\n<div class=\"table-of-contents\" style=\"background-color: #066095; color: white; padding: 10px; border-radius: 10px; margin-top: 20px; display: flex; justify-content: space-between; align-items: center; font-weight: 600;\">\n  <span style=\"flex: 1; text-align: left;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python\" style=\"color: white; text-decoration: underline;\">\u25c0 Previous<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: center;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\" style=\"color: white; text-decoration: underline;\">Python Tutorials<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: right;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-5-python-conditional-statements-if-else-and-elif\" style=\"color: white; text-decoration: underline;\">Next \u25b6<\/a>\n  <\/span>\n<\/div>\n\n\n\n\n<p>The print function is one of the most essential tools in Python, allowing you to display information and debug your code effectively. In this chapter, we\u2019ll learn the basics of print statements and explore how to print with descriptive text, use formatted string literals (F-strings), and work with format specifiers. You\u2019ll also learn how to handle quotes in strings, concatenate multiple strings, and use the <code>end<\/code> and <code>sep<\/code> arguments to control output. By the end of this chapter, you\u2019ll have a solid grasp of how to print output in Python with precision and flexibility<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<div style=\"background: linear-gradient(to right, #ADD8E6, #8A2BE2); padding: 10px; border-radius: 10px; font-weight: 600; color: black;\">\n  <h3 style=\"text-align: center; margin-top: 0;\">Table of Contents<\/h3>\n  <ul style=\"padding-left: 20px;\">\n    <li><a href=\"#Simple-Print-Statements\" style=\"color: black;\">Simple Print Statements<\/a><\/li>\n    <li><a href=\"#How-to-Print-with-Descriptive-Text\" style=\"color: black;\">How to Print with Descriptive Text<\/a><\/li>\n    <li><a href=\"#Formatted-String-Literals-or-F-strings\" style=\"color: black;\">Formatted String Literals or F-strings<\/a><\/li>\n    <li><a href=\"#Using-Format-Specifiers\" style=\"color: black;\">Using Format Specifiers<\/a><\/li>\n    <li><a href=\"#Using-String-Concatenation-in-the-Print-Function\" style=\"color: black;\">Using String Concatenation in the Print Function<\/a><\/li>\n    <li><a href=\"#Handling-Quotes-in-Strings\" style=\"color: black;\">Handling Quotes in Strings<\/a><\/li>\n    <li><a href=\"#What-is-the-end-Argument-in-the-Print-Function\" style=\"color: black;\">What is the `end` Argument in the Print Function?<\/a><\/li>\n    <li><a href=\"#What-is-the-sep-Argument-in-the-Print-Function\" style=\"color: black;\">What is the `sep` Argument in the Print Function?<\/a><\/li>\n  <\/ul>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h1 class=\"wp-block-heading has-large-font-size\"><strong>Understanding and Using the Python Print Function<\/strong> <\/h1>\n\n\n\n<p>In this chapter, we\u2019ll cover everything you need to know about Python\u2019s print function. Let\u2019s start with the syntax of a few simple print statements.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"Simple-Print-Statements\"><strong>Simple Print Statements<\/strong><\/h2>\n\n\n\n<p>You can print integers and floating-point numbers as they are. However, remember to use quotes when you are printing strings.<\/p>\n\n\n\n<p>\u00a0For example, print ( 10 ) will work, but print ( hello ) will throw an error. The correct statement is print ( \u201chello\u201d )<\/p>\n\n\n\n<p>Okay\u2026 now start with these following simple print statements and try to understand how Python displays the output.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-93cb9134dffe5e3518a15b3a8c6124bb\"><code>print ( 10 )\t\t        # Output :   10\nprint ( \"Hello\" )\t\t# Output :   Hello\nprint ( 10, 20 )\t\t# Output :   10  20\nprint ( \"Hello world\" )\t        # Output :   Hello world\nprint ( \"Hello\", 10 )\t        # Output :   Hello  10<\/code><\/pre>\n\n\n\n<p>Note that parentheses, quotes and commas are part of the syntax and are not displayed in the output.<\/p>\n\n\n\n<p><strong>Try the code yourself:<\/strong><\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/2aacd54e0c\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-default\">\n\n\n\n<p>You can print variables using the \u201cprint\u201d function. Note that variable names should not be enclosed in quotes.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-6b1dd9ef9bd9a44cfa9b6b210cd96a06\"><code>a = 10\nb = \"Hello\"\nprint ( a )\t\t# Output :   10\nprint ( a, b )\t\t# Output :    10  Hello<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"How-to-Print-with-Descriptive-Text\"><strong>How to Print with Descriptive Text<\/strong><\/h2>\n\n\n\n<p>You can use strings along with your variables if you want to print a description. For example, check the code below which mixes both strings and variables in one print statement.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-d98bd463fc79dbf44e6802c5d624f2a7\"><code>name, age = \"Peter\", 20\n\nprint ( \"Name is\",  name, \"and age is\",  age )   \n \n# Output :    Name is Peter and age is 20<\/code><\/pre>\n\n\n\n<p>Try to figure out which are the strings and which are the variables used in the above print statement.<\/p>\n\n\n\n<p><strong>Try the code yourself:<\/strong><\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/9f55365542\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<p>There are a few more ways to get the same output as the previous code. One option we have is f-strings, and the other is placeholders like %d, %s, %x, etc., known as format specifiers. Let\u2019s check f-strings first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"Formatted-String-Literals-or-F-strings\"><strong>Formatted String Literals or F-strings<\/strong><\/h2>\n\n\n\n<p>Python 3.6 introduced f-strings which provide a way to embed expressions inside string literals, using curly braces ` { } `<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-b9b24bf8e94dee73592ce4271aae350a\"><code>a = 10\nprint ( f\" a is { a } \")  \t# Output  :    a is 10\n\n#You can combine multiple variables in an f-string as well.\n\nname, age = \"Peter\", 20\nprint (f\" Name is { name } and age is { age } \")   \t\t#Output :  Name is Peter and age is 20<\/code><\/pre>\n\n\n\n<p><strong>Try to code yourself:<\/strong><\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/c6f81fa9aa\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"Using-Format-Specifiers\"><strong>Using Format Specifiers<\/strong><\/h2>\n\n\n\n<p>In this method, we can use some placeholders in the string and replace those with values of the variables. `%d`, `%s` are the two commonly used placeholders. `%d` is used for integers and `%s` for strings.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-ef1865570eea06cc21fd8468e500e8c2\"><code>name, age = \"Peter\", 20\nprint ( \"Name is  %s \" %name)   #Output :   Name is Peter\nprint ( \"Age is %d \" %age)    \t#Output :   Age is 20\n\n#Following example shows how to keep two placeholders in the same string.\n\nprint ( \"Name is  %s  and age  is  %d \u201c %(name, age) ) \t#Output :   Name is Peter and age is 20<\/code><\/pre>\n\n\n\n<p><strong>Try the code yourself:<\/strong><\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/18f544a2be\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"Using-String-Concatenation-in-the-Print-Function\"><strong>Using String Concatenation in the Print Function<\/strong><\/h2>\n\n\n\n<p>You can concatenate strings using the `+` operator.<\/p>\n\n\n\n<p>For example, `\u201dHello\u201d + \u201cWorld\u201d` gives `\u201dHelloWorld\u201d`. You can use these types of expressions directly inside the print statement.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-fa012f87d7f3f854c6517849ed01dd39\"><code>a, b = \"Hello\", \"World\"\n\nprint ( a + b )   \t# Output  :  HelloWorld<\/code><\/pre>\n\n\n\n<p>Note that concatenation with `+` only works when you use the same data types on both sides of `+`. Attempting to concatenate a string with a non-string type will result in an error.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-da2c9cca600cc12f508e6eda3c81daaf\"><code>print ( \"Hello\" + 10 )   \t# Will throw a TypeError\n\nprint ( \"Hello\" + \"10\" )   \t#Output  : Hello10<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"Handling-Quotes-in-Strings\"><strong>Handling Quotes in Strings<\/strong><\/h2>\n\n\n\n<p>You may encounter situations where you need to include quotes within your strings. You can use a backslash ( `\\` ) before quotes to avoid the special meaning of quotes, and this will display the quotes.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-80e2b6b6736b99c2cfa931d018c9b480\"><code>print(\"Interface \\\"EthernetO\\\" is up\")   \t\t\n\n#Output :  Interface \"EthernetO\" is up<\/code><\/pre>\n\n\n\n<p>In Python, you can use single quotes or double quotes to make a string. If you have used single quotes at the beginning and at the end, you can use double quotes inside the string to display it.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-08416f2254a43a6a2075f0552d118c0e\"><code>print ( 'Interface \"EthernetO\" is up' )\n\nprint (\" Interface 'EthernetO' is up\" )<\/code><\/pre>\n\n\n\n<p>\u00a0Try the code yourself:<\/p>\n\n\n\n<div style=\"text-align: center;\">\n<iframe loading=\"lazy\" src=\"https:\/\/trinket.io\/embed\/python3\/5f4d66bad7\" width=\"100%\" height=\"250\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" allowfullscreen><\/iframe>\n<\/div>\n\n\n\n<p>But using the same type of quote for both the string and the embedded quote will result in a syntax error.<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-26ddca16d76de80740cb768672a0ec97\"><code>print ( \"Interface \"EthernetO\" is up\" )\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \n\n#Output :  SyntaxError: invalid syntax<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"What-is-the-end-Argument-in-the-Print-Function\"><strong>What is the `end` Argument in the Print Function?<\/strong><\/h2>\n\n\n\n<p>By default, the `print` function ends with a newline character ( `\\n` ). You can check this by using two print statements.<\/p>\n\n\n\n<p>Try the two print commands given below:<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-02686a7eb97f7834e5457818a1153b2e\"><code>print(\"Hello\")\nprint(\"World\")\n\n#You will get the following output:\nHello\nWorld<\/code><\/pre>\n\n\n\n<p>We are getting the above output because Python adds a newline `\\n` at the end of each print statement. The first print ( \u201chello\u201d ) will get converted to print( \u201chello\\n\u201d ), so after printing the word \u201chello\u201d a new line is added. The second print statement is displayed on the second line.<\/p>\n\n\n\n<p>We can change this behavior by using the `<strong>end<\/strong>` argument.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-a5826380a071d7763a4efafe5e56dabe\"><code>print ( \"Hello\", end = \",\" )\nprint ( \"World\" )\n\n# Output:\nHello,World<\/code><\/pre>\n\n\n\n<p>In this example, the first `print` statement ends with a comma instead of a newline, so the second `print` statement continues on the same line.<\/p>\n\n\n\n<p>You can use any string for the `<strong>end<\/strong>` argument.<\/p>\n\n\n\n<p>For example:<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-bec69cfffc49596ac8e361d64baaee43\"><code>print(\"Hello\", end=\"---\")\n\nprint(\"World\")\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# Output\u00a0 :\u00a0\u00a0 Hello---World<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\">\n\n\n\n<h2 class=\"wp-block-heading has-large-font-size\" id=\"What-is-the-sep-Argument-in-the-Print-Function\"><strong>What is the `sep` Argument in the Print Function?<\/strong><\/h2>\n\n\n\n<p>You would have noticed that a space is added between the arguments in the print function.<\/p>\n\n\n\n<p>For example,<\/p>\n\n\n\n<pre class=\"wp-block-code has-pale-cyan-blue-color has-foreground-background-color has-text-color has-background has-link-color wp-elements-07b94a04aa8020fd8207e3e12a085056\"><code>print ( \"Learning\", \"Python\", \"Basics\" )  \t\t\t#Output : Learning Python Basics\n\nPrint ( \"Learning\", \"Python\", \"Basics\", sep=\"-\")\u00a0 \n#Output: Learning-Python-Basics<\/code><\/pre>\n\n\n\n<p>In the above code  `<strong>sep<\/strong>` argument is used to specify which character has to be used between the arguments.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\">\n\n\n\n<div class=\"table-of-contents\" style=\"background-color: #066095; color: white; padding: 10px; border-radius: 10px; margin-top: 20px; display: flex; justify-content: space-between; align-items: center; font-weight: 600;\">\n  <span style=\"flex: 1; text-align: left;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-3-working-with-variables-in-python\" style=\"color: white; text-decoration: underline;\">\u25c0 Previous<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: center;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\" style=\"color: white; text-decoration: underline;\">Python Tutorials<\/a>\n  <\/span>\n  \n  <span style=\"flex: 1; text-align: right;\">\n    <a href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-5-python-conditional-statements-if-else-and-elif\" style=\"color: white; text-decoration: underline;\">Next \u25b6<\/a>\n  <\/span>\n<\/div>\n\n<\/body>","protected":false},"excerpt":{"rendered":"<p>\u25c0 Previous Python Tutorials Next \u25b6 The print function is one of the most essential tools in Python, allowing you to display information and debug your code effectively. In this chapter, we\u2019ll learn the basics of print statements and explore how to print with descriptive text, use formatted string literals (F-strings), and work with format [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":740,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-post-with-sidebar2","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[46],"tags":[256,254,258,260,253,255,259,257],"class_list":["post-110","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-tutorials","tag-f-strings-in-python","tag-format-specifiers-in-python","tag-print-statements-in-python","tag-printing-in-python","tag-python-end-argument","tag-python-print-function","tag-python-sep-argument","tag-string-concatenation-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Chapter 4: Mastering the Print Function in Python - Tutorials<\/title>\n<meta name=\"description\" content=\"Learn how to master Python&#039;s print function. This guide covers print statements, F-strings, format specifiers, string concatenation, and using the &#039;end&#039; and &#039;sep&#039; arguments.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mastering the Print Function in Python \u2013 A Complete Guide\" \/>\n<meta property=\"og:description\" content=\"Learn how to use Python\u2019s print function effectively. Explore print statements, F-strings, format specifiers, string concatenation, and more in this detailed guide\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python\" \/>\n<meta property=\"og:site_name\" content=\"Tutorials\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/zframez\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-09-04T18:12:21+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-16T15:49:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"759\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"sajith achipra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@zframez\" \/>\n<meta name=\"twitter:site\" content=\"@zframez\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"sajith achipra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python\"},\"author\":{\"name\":\"sajith achipra\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/person\\\/8b3b88007644501771d2452d3cc80f41\"},\"headline\":\"Chapter 4: Mastering the Print Function in Python\",\"datePublished\":\"2024-09-04T18:12:21+00:00\",\"dateModified\":\"2024-10-16T15:49:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python\"},\"wordCount\":813,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/print-function-.png?fit=1350%2C759&ssl=1\",\"keywords\":[\"F-strings in Python\",\"Format Specifiers in Python\",\"Print Statements in Python\",\"Printing in Python\",\"Python end Argument\",\"Python Print Function\",\"Python sep Argument\",\"String Concatenation in Python\"],\"articleSection\":[\"python tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python\",\"url\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python\",\"name\":\"Chapter 4: Mastering the Print Function in Python - Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/print-function-.png?fit=1350%2C759&ssl=1\",\"datePublished\":\"2024-09-04T18:12:21+00:00\",\"dateModified\":\"2024-10-16T15:49:17+00:00\",\"description\":\"Learn how to master Python's print function. This guide covers print statements, F-strings, format specifiers, string concatenation, and using the 'end' and 'sep' arguments.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/print-function-.png?fit=1350%2C759&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/09\\\/print-function-.png?fit=1350%2C759&ssl=1\",\"width\":1350,\"height\":759,\"caption\":\"Running a print('Hello World!') statement in Python interpreter mode\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/python-tutorials\\\/chapter-4-mastering-the-print-function-in-python#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tutorials\",\"item\":\"https:\\\/\\\/www.zframez.com\\\/articles\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Chapter 4: Mastering the Print Function in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#website\",\"url\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/\",\"name\":\"zframez tutorials\",\"description\":\"Learn networking bit by bit\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#organization\",\"name\":\"zframez technologies\",\"url\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/zframez-logo.jpg?fit=864%2C864&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/www.zframez.com\\\/articles\\\/wp-content\\\/uploads\\\/2024\\\/07\\\/zframez-logo.jpg?fit=864%2C864&ssl=1\",\"width\":864,\"height\":864,\"caption\":\"zframez technologies\"},\"image\":{\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/zframez\\\/\",\"https:\\\/\\\/x.com\\\/zframez\",\"https:\\\/\\\/www.instagram.com\\\/zframez_technologies\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.zframez.com\\\/articles\\\/#\\\/schema\\\/person\\\/8b3b88007644501771d2452d3cc80f41\",\"name\":\"sajith achipra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g\",\"caption\":\"sajith achipra\"},\"sameAs\":[\"http:\\\/\\\/www.zframez.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Chapter 4: Mastering the Print Function in Python - Tutorials","description":"Learn how to master Python's print function. This guide covers print statements, F-strings, format specifiers, string concatenation, and using the 'end' and 'sep' arguments.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python","og_locale":"en_US","og_type":"article","og_title":"Mastering the Print Function in Python \u2013 A Complete Guide","og_description":"Learn how to use Python\u2019s print function effectively. Explore print statements, F-strings, format specifiers, string concatenation, and more in this detailed guide","og_url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python","og_site_name":"Tutorials","article_publisher":"https:\/\/www.facebook.com\/zframez\/","article_published_time":"2024-09-04T18:12:21+00:00","article_modified_time":"2024-10-16T15:49:17+00:00","og_image":[{"width":1350,"height":759,"url":"https:\/\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png","type":"image\/png"}],"author":"sajith achipra","twitter_card":"summary_large_image","twitter_creator":"@zframez","twitter_site":"@zframez","twitter_misc":{"Written by":"sajith achipra","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#article","isPartOf":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python"},"author":{"name":"sajith achipra","@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/person\/8b3b88007644501771d2452d3cc80f41"},"headline":"Chapter 4: Mastering the Print Function in Python","datePublished":"2024-09-04T18:12:21+00:00","dateModified":"2024-10-16T15:49:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python"},"wordCount":813,"commentCount":0,"publisher":{"@id":"https:\/\/www.zframez.com\/articles\/#organization"},"image":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1350%2C759&ssl=1","keywords":["F-strings in Python","Format Specifiers in Python","Print Statements in Python","Printing in Python","Python end Argument","Python Print Function","Python sep Argument","String Concatenation in Python"],"articleSection":["python tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python","url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python","name":"Chapter 4: Mastering the Print Function in Python - Tutorials","isPartOf":{"@id":"https:\/\/www.zframez.com\/articles\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#primaryimage"},"image":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1350%2C759&ssl=1","datePublished":"2024-09-04T18:12:21+00:00","dateModified":"2024-10-16T15:49:17+00:00","description":"Learn how to master Python's print function. This guide covers print statements, F-strings, format specifiers, string concatenation, and using the 'end' and 'sep' arguments.","breadcrumb":{"@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#primaryimage","url":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1350%2C759&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1350%2C759&ssl=1","width":1350,"height":759,"caption":"Running a print('Hello World!') statement in Python interpreter mode"},{"@type":"BreadcrumbList","@id":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-4-mastering-the-print-function-in-python#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Tutorials","item":"https:\/\/www.zframez.com\/articles"},{"@type":"ListItem","position":2,"name":"Chapter 4: Mastering the Print Function in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.zframez.com\/articles\/#website","url":"https:\/\/www.zframez.com\/articles\/","name":"zframez tutorials","description":"Learn networking bit by bit","publisher":{"@id":"https:\/\/www.zframez.com\/articles\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.zframez.com\/articles\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.zframez.com\/articles\/#organization","name":"zframez technologies","url":"https:\/\/www.zframez.com\/articles\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/logo\/image\/","url":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/07\/zframez-logo.jpg?fit=864%2C864&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/07\/zframez-logo.jpg?fit=864%2C864&ssl=1","width":864,"height":864,"caption":"zframez technologies"},"image":{"@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/zframez\/","https:\/\/x.com\/zframez","https:\/\/www.instagram.com\/zframez_technologies\/"]},{"@type":"Person","@id":"https:\/\/www.zframez.com\/articles\/#\/schema\/person\/8b3b88007644501771d2452d3cc80f41","name":"sajith achipra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3d9f27c5311500982b6f19d03d0506f1c328f30f51d8d5f73f46577687fd81f8?s=96&d=mm&r=g","caption":"sajith achipra"},"sameAs":["http:\/\/www.zframez.com"]}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/print-function-.png?fit=1350%2C759&ssl=1","jetpack-related-posts":[{"id":901,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-6-python-while-and-for-loops-examples-and-explanations","url_meta":{"origin":110,"position":0},"title":"Chapter 6: Python While and For Loops: Examples and Explanations","author":"sajith achipra","date":"September 15, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Python While and For Loops In this chapter of our Python tutorial series, we will explore two essential looping structures in Python: while loops and for loops. Loops are a fundamental part of programming, allowing you to execute a block of code repeatedly under\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":904,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-7-working-with-strings-in-python","url_meta":{"origin":110,"position":1},"title":"Chapter 7: Working with Strings in Python","author":"sajith achipra","date":"September 15, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Python String Manipulation: Methods and Examples In Chapter 7, we\u2019ll be looking at how to work with strings in Python. Strings are used everywhere in programming, and Python provides a lot of methods to make string manipulation easy. In this chapter, we\u2019ll explore methods\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":917,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-11-python-file-handling-reading-writing-and-managing-files","url_meta":{"origin":110,"position":2},"title":"Chapter 11: Python File Handling -Reading, Writing, and Managing Files","author":"sajith achipra","date":"September 15, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Working with File Operations in Python In this chapter, we\u2019ll explore how to work with files in Python, including reading, writing, and managing files efficiently. Files are often used to store inputs or outputs during script execution, and Python\u2019s built-in support for file handling\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":751,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-5-python-conditional-statements-if-else-and-elif","url_meta":{"origin":110,"position":3},"title":"Chapter 5:Python Conditional Statements: if, else, and elif","author":"sajith achipra","date":"September 11, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Table of Contents Introduction to Python `if` and `else` Understanding Python `if` Syntax Multiple Lines of Code in an `if` Statement Using `else` with `if` How does Python know when the `if` code block is finished? Using the `pass` Statement Checking Odd and Even\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"Block diagram illustrating an if expression and corresponding code block in Python, with a Python icon in the top right corner.","src":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.zframez.com\/articles\/wp-content\/uploads\/2024\/09\/Python-conditional-statments-if-else.jpg?fit=1200%2C675&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":913,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-10-python-functions-variable-scopes-and-lambda-expressions","url_meta":{"origin":110,"position":4},"title":"Chapter 10: Python Functions, Variable Scopes, and Lambda Expressions","author":"sajith achipra","date":"September 15, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Understanding Functions, Variable Scopes, and Lambda Functions in Python In this chapter, we\u2019ll go through functions, one of the core building blocks in Python. Functions allow you to organize code, reuse logic, and make your programs cleaner and more efficient. In this chapter, we\u2019ll\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":908,"url":"https:\/\/www.zframez.com\/articles\/python-tutorials\/chapter-8-python-lists-and-tuples-operations-and-methods","url_meta":{"origin":110,"position":5},"title":"Chapter 8: Python Lists and Tuples -Operations and Methods","author":"sajith achipra","date":"September 15, 2024","format":false,"excerpt":"\u25c0 Previous Python Tutorials Next \u25b6 Working with Lists and Tuples in Python In this chapter, we\u2019ll explore two important data structures in Python: lists and tuples. Lists allow you to store a collection of items that can be modified, while tuples are immutable, meaning their elements cannot be changed.\u2026","rel":"","context":"In &quot;python tutorials&quot;","block_context":{"text":"python tutorials","link":"https:\/\/www.zframez.com\/articles\/category\/python-tutorials"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts\/110","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/comments?post=110"}],"version-history":[{"count":5,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts\/110\/revisions"}],"predecessor-version":[{"id":1080,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/posts\/110\/revisions\/1080"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/media\/740"}],"wp:attachment":[{"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/media?parent=110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/categories?post=110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.zframez.com\/articles\/wp-json\/wp\/v2\/tags?post=110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}