{"id":2313,"date":"2026-09-30T12:52:25","date_gmt":"2026-09-30T12:52:25","guid":{"rendered":"https:\/\/entri.app\/explore\/?post_type=curriculum&#038;p=2313"},"modified":"2026-09-30T12:52:25","modified_gmt":"2026-09-30T12:52:25","slug":"python-print-function","status":"publish","type":"curriculum","link":"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/","title":{"rendered":"Python Print Function"},"content":{"rendered":"<h2><strong><b>What Is print() in Python?<\/b><\/strong><\/h2>\n<p><strong><b>print()<\/b><\/strong>\u00a0is a built-in function that writes values to the standard output (your screen or terminal). Its full signature is:<\/p>\n<p>print(*objects, sep=&#8221; &#8220;, end=&#8221;\\n&#8221;, file=sys.stdout, flush=False)<\/p>\n<p>The simplest use displays a string literal. Single and double quotes work the same way:<\/p>\n<p>print(&#8220;Hello&#8221;)<\/p>\n<p>print(&#8216;Hello&#8217;)<\/p>\n<p># Output:<\/p>\n<p># Hello<\/p>\n<p># Hello<\/p>\n<h2><strong><b>How to Print a Variable in Python<\/b><\/strong><\/h2>\n<p>character:<\/p>\n<p>x = &#8220;awesome&#8221;<\/p>\n<p>print(&#8220;Python is &#8221; + x) \u00a0\u00a0# Python is awesome<\/p>\n<p>You cannot use +\u00a0to join a string and a number. print(5 + &#8220;John&#8221;)\u00a0raises TypeError: unsupported operand type(s) for +: &#8216;int&#8217; and &#8216;str&#8217;.<\/p>\n<p>The easier way is to pass values separated by commas; print() converts each to text and adds a space between them:<\/p>\n<p>name = &#8220;Asha&#8221;<\/p>\n<p>age = 22<\/p>\n<p>print(&#8220;Name:&#8221;, name, &#8220;Age:&#8221;, age) \u00a0\u00a0# Name: Asha Age: 22<\/p>\n<h2><strong><b>How Do You Format Output with format() and f-strings?<\/b><\/strong><\/h2>\n<p>The <strong><b>format()<\/b><\/strong>\u00a0method inserts values into {}\u00a0placeholders. Index numbers such as {0}\u00a0control which argument goes where:<\/p>\n<p>quantity = 3<\/p>\n<p>itemno = 567<\/p>\n<p>price = 49.95<\/p>\n<p>myorder = &#8220;I want to pay {2} dollars for {0} pieces of item {1}.&#8221;<\/p>\n<p>print(myorder.format(quantity, itemno, price))<\/p>\n<p>An <strong><b>f-string<\/b><\/strong>\u00a0(formatted string literal, Python 3.6+) is a string prefixed with f. Expressions inside {}\u00a0are evaluated and inserted directly, which makes f-strings the shortest and most readable option. The &#8220;f&#8221; in f&#8221;&#8230;&#8221;\u00a0stands for &#8220;formatted&#8221;.<\/p>\n<p>name = &#8220;Asha&#8221;<\/p>\n<p>price = 49.955<\/p>\n<p>print(f&#8221;Hello {name}, total = {price:.2f}&#8221;) \u00a0\u00a0# Hello Asha, total = 49.96<\/p>\n<h2><strong><b>How to Print in the Same Line in Python (the end Parameter)<\/b><\/strong><\/h2>\n<p>By default print() ends with a newline (end=&#8221;\\n&#8221;). Change end\u00a0to keep the next output on the same line:<\/p>\n<p>for i in range(1, 4):<\/p>\n<p>print(i, end=&#8221; &#8220;)<\/p>\n<p># Output: 1 2 3<\/p>\n<p>The end\u00a0parameter sets what is printed after the last value. end=&#8221;&#8221;\u00a0prints nothing, end=&#8221;, &#8221;\u00a0adds a comma, and the default adds a line break.<\/p>\n<h2><strong><b>How to Print Vertically in Python (the sep Parameter)<\/b><\/strong><\/h2>\n<p>To print values one below another, set sep=&#8221;\\n&#8221;, or loop over the values:<\/p>\n<p>print(&#8220;a&#8221;, &#8220;b&#8221;, &#8220;c&#8221;, sep=&#8221;\\n&#8221;)<\/p>\n<p>&nbsp;<\/p>\n<p>for ch in &#8220;PY&#8221;:<\/p>\n<p>print(ch)<\/p>\n<p># Both print each item on its own line<\/p>\n<h2><strong><b>How to Print Formatted Output in Python: A Receipt Example<\/b><\/strong><\/h2>\n<p><strong><b>Part 2 \u2014 Tutorial<\/b><\/strong><\/p>\n<p>In this tutorial you will print a small shopping receipt using plain print(), comma-separated values, an f-string with 2-decimal formatting, and the end and sep parameters. It takes about 10 minutes and 5 steps.<\/p>\n<h3><strong><b>Prerequisites<\/b><\/strong><\/h3>\n<ul>\n<li>Python 3 installed and able to run a .py<\/li>\n<li>Know how to create a variable (x = 5).<\/li>\n<\/ul>\n<h3><strong><b>Steps<\/b><\/strong><\/h3>\n<p><strong><b>Step 1: Print a heading<\/b><\/strong><\/p>\n<p>Start with a simple string.<\/p>\n<p>print(&#8220;=== ENTRI STORE ===&#8221;)<\/p>\n<p><strong><b>Step 2: Store values in variables<\/b><\/strong><\/p>\n<p>Keep the data separate from the printing.<\/p>\n<p>item = &#8220;Notebook&#8221;<\/p>\n<p>qty = 3<\/p>\n<p>price = 49.5<\/p>\n<p><strong><b>Step 3: Print values with commas<\/b><\/strong><\/p>\n<p>Commas insert a space and convert numbers automatically, so no TypeError.<\/p>\n<p>print(&#8220;Item:&#8221;, item, &#8220;| Qty:&#8221;, qty)<\/p>\n<p><strong><b>Step 4: Format the total with an f-string<\/b><\/strong><\/p>\n<p>Use :.2f to show exactly two decimal places.<\/p>\n<p>total = qty * price<\/p>\n<p>print(f&#8221;Total: Rs. {total:.2f}&#8221;) \u00a0\u00a0# Total: Rs. 148.50<\/p>\n<p><strong><b>Step 5: Use end and sep for layout<\/b><\/strong><\/p>\n<p>Print a divider on one line and a vertical thank-you message.<\/p>\n<p>for _ in range(20):<\/p>\n<p>print(&#8220;-&#8220;, end=&#8221;&#8221;)<\/p>\n<p>print()<\/p>\n","protected":false},"excerpt":{"rendered":"<p>What Is print() in Python? print()\u00a0is a built-in function that writes values to the standard output (your screen or terminal). Its full signature is: print(*objects, sep=&#8221; &#8220;, end=&#8221;\\n&#8221;, file=sys.stdout, flush=False) The simplest use displays a string literal. Single and double quotes work the same way: print(&#8220;Hello&#8221;) print(&#8216;Hello&#8217;) # Output: # Hello # Hello How to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"template":"","meta":{"_acf_changed":false},"curriculum-category":[150,149,148],"custom_linking_tags":[],"class_list":["post-2313","curriculum","type-curriculum","status-publish","hentry","curriculum-category-python-foundations","curriculum-category-python-tutorials","curriculum-category-python-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Print Function<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Print Function\" \/>\n<meta property=\"og:description\" content=\"What Is print() in Python? print()\u00a0is a built-in function that writes values to the standard output (your screen or terminal). Its full signature is: print(*objects, sep=&#8221; &#8220;, end=&#8221;n&#8221;, file=sys.stdout, flush=False) The simplest use displays a string literal. Single and double quotes work the same way: print(&#8220;Hello&#8221;) print(&#8216;Hello&#8217;) # Output: # Hello # Hello How to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/\" \/>\n<meta property=\"og:site_name\" content=\"Entri Free Materials\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/\",\"url\":\"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/\",\"name\":\"Python Print Function\",\"isPartOf\":{\"@id\":\"https:\/\/entri.app\/explore\/#website\"},\"datePublished\":\"2026-09-30T12:52:25+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/entri.app\/explore\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Print Function\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/entri.app\/explore\/#website\",\"url\":\"https:\/\/entri.app\/explore\/\",\"name\":\"Entri Free Materials\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/entri.app\/explore\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/entri.app\/explore\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/entri.app\/explore\/#organization\",\"name\":\"Entri Free Materials\",\"url\":\"https:\/\/entri.app\/explore\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg\",\"contentUrl\":\"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg\",\"caption\":\"Entri Free Materials\"},\"image\":{\"@id\":\"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Print Function","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:\/\/entri.app\/explore\/python-programming\/python-print-function\/","og_locale":"en_US","og_type":"article","og_title":"Python Print Function","og_description":"What Is print() in Python? print()\u00a0is a built-in function that writes values to the standard output (your screen or terminal). Its full signature is: print(*objects, sep=&#8221; &#8220;, end=&#8221;n&#8221;, file=sys.stdout, flush=False) The simplest use displays a string literal. Single and double quotes work the same way: print(&#8220;Hello&#8221;) print(&#8216;Hello&#8217;) # Output: # Hello # Hello How to [&hellip;]","og_url":"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/","og_site_name":"Entri Free Materials","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/","url":"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/","name":"Python Print Function","isPartOf":{"@id":"https:\/\/entri.app\/explore\/#website"},"datePublished":"2026-09-30T12:52:25+00:00","breadcrumb":{"@id":"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/entri.app\/explore\/python-programming\/python-print-function\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/entri.app\/explore\/python-programming\/python-print-function\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/entri.app\/explore\/"},{"@type":"ListItem","position":2,"name":"Python Print Function"}]},{"@type":"WebSite","@id":"https:\/\/entri.app\/explore\/#website","url":"https:\/\/entri.app\/explore\/","name":"Entri Free Materials","description":"","publisher":{"@id":"https:\/\/entri.app\/explore\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/entri.app\/explore\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/entri.app\/explore\/#organization","name":"Entri Free Materials","url":"https:\/\/entri.app\/explore\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/","url":"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg","contentUrl":"https:\/\/wp-cdn.entri.app\/explore\/2025\/03\/logo.svg","caption":"Entri Free Materials"},"image":{"@id":"https:\/\/entri.app\/explore\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/curriculum\/2313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/curriculum"}],"about":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/types\/curriculum"}],"author":[{"embeddable":true,"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/users\/2"}],"wp:attachment":[{"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/media?parent=2313"}],"wp:term":[{"taxonomy":"curriculum-category","embeddable":true,"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/curriculum-category?post=2313"},{"taxonomy":"custom_linking_tags","embeddable":true,"href":"https:\/\/entri.app\/explore\/wp-json\/wp\/v2\/custom_linking_tags?post=2313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}