{"id":810,"date":"2021-11-02T11:31:49","date_gmt":"2021-11-02T11:31:49","guid":{"rendered":"https:\/\/ethosspace.com\/programmers\/?p=810"},"modified":"2021-11-05T11:34:19","modified_gmt":"2021-11-05T11:34:19","slug":"print-function-with-different-examples-in-detail","status":"publish","type":"post","link":"https:\/\/ethosspace.com\/programmers\/print-function-with-different-examples-in-detail\/","title":{"rendered":"Print function with different examples in detail"},"content":{"rendered":"\n<p>Print statement in python is not reserved word nor a statement. Print is built in function call which run as expression statement.<br><\/p>\n\n\n\n<p>The interactive session automatically prints the results of expressions you type, you don\u2019t usually need to<br>say \u201cprint\u201d explicitly at this prompt:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>&gt;&gt;&gt;ethosspace = &#39;Testing Services&#39;\n&gt;&gt;&gt;ethosspace  \n&#39; Testing Services &#39;<\/code><\/pre><\/div>\n\n\n\n<p>So print function used in files not on interactive prompt.<\/p>\n\n\n\n<p><strong>Syntax <\/strong><br><strong>print([object, \u2026][, sep=&#8217; &#8216;][, end=&#8217;\\n&#8217;][, file=sys.stdout])<\/strong><br><br><strong>print<em>(object(s)<\/em>, sep=<em>separator<\/em>, end=<em>end<\/em>, file=<em>file<\/em>, flush=<em>flush<\/em>)<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-left\">Items in square brackets are optional and may be omitted in a given call, and values after = give argument defaults.<br>In English, this built-in function prints the textual representation of one or more objects separated by the string sep and followed by the string end to the stream file.<\/p>\n\n\n\n<p><strong>SEP<\/strong> is a string inserted between each object\u2019s text, which defaults to a <strong>single space if not passed<\/strong>; passing an empty string suppresses separators altogether.<\/p>\n\n\n\n<p><strong>END<\/strong> is a string added at the end of the printed text, which defaults to a <strong>\\n newline character if not passed<\/strong>. Passing an empty string avoids dropping down to the next output line.<\/p>\n\n\n\n<p><strong>FILE<\/strong> specifies the file, standard stream, or other file-like object to which the text will be sent; it defaults to the sys.stdout standard output stream if not passed.<\/p>\n\n\n\n<p>Here are the real time example of print function.<\/p>\n\n\n\n<p>print function with no parameter print the empty line<\/p>\n\n\n\n<p>&gt;&gt;&gt;print()<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>To print blank line no need to pass any parameter by default print without any parameter prints blank line.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>&gt;&gt;&gt; a=9\n &gt;&gt;&gt; b=&#39;Testing&#39;\n &gt;&gt;&gt; c=[&#39;Prog&#39;]\n &gt;&gt;&gt; print(a,b,c)\n         9 Testing [&#39;Prog&#39;]<\/code><\/pre><\/div>\n\n\n\n<p>So while printing 3 objects print function added empty space between those three objects. So in place of empty space if we want different separator then we can use below syntax.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code> &gt;&gt;&gt; print(a,b,c,sep=&#39; =&gt; &#39;)\n          9 =&gt; Testing =&gt; [&#39;Prog&#39;]<\/code><\/pre><\/div>\n\n\n\n<p>Output is now separated with  separator =&gt; which we provided.<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>By default, print adds an end-of-line character to terminate the output line. <\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>&gt;&gt;&gt;print (&#39;ethosspace&#39;); print(&#39;leading software testing provider&#39;)\n        ethosspace\n        leading software testing provider<\/code><\/pre><\/div>\n\n\n\n<p>So if we don&#8217;t need new line then we will use end parameter here<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>&gt;&gt;&gt;print (\u2018ethosspace\u2019,end=\u201d); print(\u2018 leading software testing provider\u2019)\n\nethosspace leading software testing provider<\/code><\/pre><\/div>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Example of variable, %d and % in print statement. Use of variable in between sentence in print statement.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>&gt;&gt;&gt;x=5\n&gt;&gt;&gt;y=8\n&gt;&gt;&gt;z=2 * (x+y)\n&gt;&gt;&gt;print(&#39;A rectangle %d by %d has a perimeter of %d units.&#39;%(x,y,z))\nA rectangle 5 by 8 has a perimeter of 26 units.<\/code><\/pre><\/div>\n\n\n\n<p>Use <a href=\"https:\/\/ethosspace.com\/programmers\/free-online-python-compiler-interpreter\/\" title=\"Free Online Python Compiler (Interpreter)\">online free python compiler<\/a> to run program from anywhere.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Print statement in python is not reserved word nor a statement. Print is built in function call which run as expression statement. The interactive session automatically prints the results of expressions you type, you don\u2019t usually need tosay \u201cprint\u201d explicitly at this prompt: So print function used in files not on interactive prompt. Syntax print([object, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","footnotes":""},"categories":[11],"tags":[],"class_list":["post-810","post","type-post","status-publish","format-standard","hentry","category-running-code-and-program"],"aioseo_notices":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"sparkling-featured":false,"sparkling-featured-fullwidth":false,"tab-small":false},"uagb_author_info":{"display_name":"program45_-rt8nb","author_link":"https:\/\/ethosspace.com\/programmers\/author\/program45_-rt8nb\/"},"uagb_comment_info":0,"uagb_excerpt":"Print statement in python is not reserved word nor a statement. Print is built in function call which run as expression statement. The interactive session automatically prints the results of expressions you type, you don\u2019t usually need tosay \u201cprint\u201d explicitly at this prompt: So print function used in files not on interactive prompt. Syntax print([object,&hellip;","_links":{"self":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/810","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/comments?post=810"}],"version-history":[{"count":11,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/810\/revisions"}],"predecessor-version":[{"id":922,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/posts\/810\/revisions\/922"}],"wp:attachment":[{"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/media?parent=810"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/categories?post=810"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ethosspace.com\/programmers\/wp-json\/wp\/v2\/tags?post=810"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}