{"id":11458,"date":"2015-07-20T17:30:08","date_gmt":"2015-07-20T17:30:08","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=11458"},"modified":"2015-07-20T17:30:08","modified_gmt":"2015-07-20T17:30:08","slug":"python-a-few-comments-about-the-print-command","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/python-a-few-comments-about-the-print-command\/","title":{"rendered":"Python:  a few comments about the print command"},"content":{"rendered":"<h1>The tutor seeks to clarify some ideas about Python&#8217;s <span style=\"font-family:monospace\">print<\/span> command.<\/h1>\n<p>I refreshed Python on one of my computers yesterday; I uninstalled Python 2.7, then installed Python 3.4 instead.  To do so, I went to <a href=\"https:\/\/www.python.org\/\">python.org<\/a>.  I was using a Windows 7 computer at the time; the site suggested a download for me, so I just followed its lead.  Later I tried a test script.  The whole process took inside of 10 minutes.  Everything works flawlessly, so far as I know.<\/p>\n<p>Of course, there are differences between Python 2.x and 3.x.  A key one that might affect people still running Python 2.x concerns the <span style=\"font-family:monospace\">print<\/span> command.<\/p>\n<p>In Python 2.x, <span style=\"font-family:monospace\">print<\/span> doesn&#8217;t require brackets.  Therefore,<\/p>\n<p><span style=\"font-family:monospace\">print &#8220;Hello!&#8221;<span style=\"color:green\">&nbsp;&nbsp;&nbsp;#2.x<\/span><\/span><\/p>\n<p>works perfectly.  However, in Python 3.x, brackets are required:<\/p>\n<p><span style=\"font-family:monospace\">print(&#8220;Hello!&#8221;)<span style=\"color:green\">&nbsp;&nbsp;&nbsp;#3.x<\/span><\/span><\/p>\n<p>In 2.x, <span style=\"font-family:monospace\">print<\/span> always attaches a newline.  Therefore,<\/p>\n<p><span style=\"font-family:monospace\">print &#8220;Hello!&#8221;<\/span><br \/>\n<span style=\"font-family:monospace\">print &#8220;Ciao!&#8221;<\/span><\/p>\n<p>will give the output<br \/>\n<span style=\"font-family:monospace\"><br \/>\nHello!<br \/>\nCiao!<br \/>\n<\/span><\/p>\n<p>In 3.x, you can stop the newline&#8217;s being added with <span style=\"font-family:monospace\">end=&#8221; &#8220;<\/span>:<br \/>\n<span style=\"font-family:monospace\"><br \/>\nprint(&#8220;Hello!&#8221;, end=&#8221; &#8220;)<br \/>\nprint(&#8220;Ciao!&#8221;)<\/span><\/p>\n<p>gives the output<br \/>\n<span style=\"font-family:monospace\"><br \/>\nHello! Ciao!<br \/>\n<\/span><\/p>\n<p>To my knowledge, the <span style=\"font-family:monospace\">end=&#8221; &#8220;<\/span> trick doesn&#8217;t work in Python 2.x.<\/p>\n<p>HTH:)<\/p>\n<p>Source:<\/p>\n<p>Donaldson, Toby.  <u>Python<\/u>, 3rd Ed.  Peachpit Press, 2014.<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The tutor seeks to clarify some ideas about Python&#8217;s print command. I refreshed Python on one of my computers yesterday; I uninstalled Python 2.7, then installed Python 3.4 instead. To do so, I went to python.org. I was using a &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/python-a-few-comments-about-the-print-command\/\"> <span class=\"screen-reader-text\">Python:  a few comments about the print command<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[930,938,939,937],"class_list":["post-11458","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-python","tag-python-2-x-vs-3-x","tag-python-end","tag-python-print-command"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/11458","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=11458"}],"version-history":[{"count":21,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/11458\/revisions"}],"predecessor-version":[{"id":11479,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/11458\/revisions\/11479"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=11458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=11458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=11458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}