{"id":5752,"date":"2022-02-05T18:13:16","date_gmt":"2022-02-05T17:13:16","guid":{"rendered":"http:\/\/miro.borodziuk.eu\/?p=5752"},"modified":"2024-05-28T05:51:06","modified_gmt":"2024-05-28T03:51:06","slug":"comments","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2022\/02\/05\/comments\/","title":{"rendered":"Comments"},"content":{"rendered":"<div class=\"small-12 large-6 columns\">\n<p>1. Comments can be used to leave additional information in code. They are omitted at runtime. The information left in source code is addressed to human readers. In Python, a comment is a piece of text that begins with <code>#<\/code>. The comment extends to the end of line.<\/p>\n<p><!--more--><\/p>\n<p>2. If you want to place a comment that spans several lines, you need to place <code>#<\/code> in front of them all.<\/p>\n<p>Moreover, you can use a comment to mark a piece of code that is not needed at the moment (see the last line of the snippet below), e.g.:<\/p>\n<pre class=\"lang:default decode:true \"># This program prints\r\n# an introduction to the screen.\r\nprint(\"Hello!\") # Invoking the print() function\r\n# print(\"I'm Python.\")<\/pre>\n<p>&nbsp;<\/p>\n<p>3. Whenever possible and justified, you should give <strong>self-commenting names<\/strong> to variables, e.g., if you&#8217;re using two variables to store a length and width of something, the variable names <code>length<\/code> and <code>width<\/code> may be a better choice than <code>myvar1<\/code> and <code>myvar2<\/code>.<\/p>\n<p>4. It&#8217;s important to use comments to make programs easier to understand, and to use readable and meaningful variable names in code. However, it&#8217;s equally important <strong>not to use<\/strong> variable names that are confusing, or leave comments that contain wrong or incorrect information!<\/p>\n<p>5. Comments can be important when <i>you<\/i> are reading your own code after some time (trust us, developers do forget what their own code does), and when <i>others<\/i> are reading your code (can help them understand what your programs do and how they do it more quickly).<\/p>\n<\/div>\n<div class=\"small-12 large-6 columns\">\n<p>&nbsp;<\/p>\n<p><strong>Exercise 1<\/strong><\/p>\n<p>What is the output of the following snippet?<\/p>\n<pre class=\"lang:default decode:true\"># print(\"String #1\")\r\nprint(\"String #2\")<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<p id=\"sol\"><code class=\"codep \">String #2<\/code><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Exercise 2<\/strong><\/p>\n<p>What will happen when you run the following code?<\/p>\n<pre class=\"lang:default decode:true \"># This is\r\na multiline\r\ncomment. #\r\n\r\nprint(\"Hello!\")<\/pre>\n<p>&nbsp;<\/p>\n<p id=\"sol2\"><code class=\"codep \">SyntaxError: invalid syntax<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. Comments can be used to leave additional information in code. They are omitted at runtime. The information left in source code is addressed to human readers. In Python, a comment is a piece of text that begins with #. The comment extends to the end of line.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5752"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=5752"}],"version-history":[{"count":5,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5752\/revisions"}],"predecessor-version":[{"id":5840,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5752\/revisions\/5840"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=5752"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=5752"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=5752"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}