{"id":21399,"date":"2023-08-22T00:36:46","date_gmt":"2023-08-21T19:06:46","guid":{"rendered":"https:\/\/codeforgeek.com\/?p=21399"},"modified":"2025-08-06T00:39:40","modified_gmt":"2025-08-05T19:09:40","slug":"python-comments","status":"publish","type":"post","link":"https:\/\/codeforgeek.com\/python-comments\/","title":{"rendered":"An Introduction to Python Comments"},"content":{"rendered":"\n<p>Looking at pages of codes can sometimes be exhaustive for an average human. After all, code is just a language used to make machines understand our requirements. Being someone who often finds out of depth when the core language skills of our native tongue are tested, it is no wonder that we find it difficult to put up with coding which is comparatively new to mankind. So, we resort to our own language to assist our understanding of codes.<\/p>\n\n\n\n<p>Yep! <strong>Comments <\/strong>play an integral role in conveying to the user the purpose of any particular code in a program. Let us learn about comments in Python in detail in this article.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">What are Comments &#038; Why do we need them?<\/h2>\n\n\n\n<p>Comments are textual descriptions within a program that describes the purpose or function of any particular code in a program. That being said, these textual data are skipped by the Python compiler when the program is run making it a stealthy accomplice<em>.<\/em><\/p>\n\n\n\n<p>Not all programs are crisp &#038; short with a few lines of code unless it\u2019s some examples for a demonstration to a school kid. Realtime applications involve programs that when printed can be the equivalent of volumes of books. Thusly, to understand the interlinks &#038; functionality of the codes in different sections, it is recommended for the developer to leave a few words about what-is-what &amp; which-is-which.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">How to Identify a Comment?<\/h2>\n\n\n\n<p>All comments in Python start with a hash<strong> (#)<\/strong> making it all the way easier to be spotted by the developer or other users and at the same ignored by the compiler during execution of the program. There is also another way of commenting using the triple double quotes <strong>(&#8221; &#8221; &#8220;) <\/strong>which shall be explained in the later sections of this article.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Implications of Deploying Comments<\/h2>\n\n\n\n<p><strong>Listed below are some of the key uses of deploying comments in your Python program:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Serves as a documentation of the program explaining its coding.<\/li>\n\n\n\n<li>Provides more information about the complicated logic behind the codes, thereby assisting in understanding them.<\/li>\n\n\n\n<li>Supports during times of code edits.<\/li>\n\n\n\n<li>Reduces time spent when spinning off an update to the existing program.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Creating Comments \u2013 Best Practices<\/h2>\n\n\n\n<p>The objective behind comments is to provide a glimpse of logic, not write paragraphs explaining the same. So, it is imperative that they are kept short and crisp. There are also no special locations where the comments are to be deployed in a program. One can feel free to put a comment wherever required, but not repeat them wherever the code repeats.<\/p>\n\n\n\n<p>The other important part about writing comments is not to write them. You read that right! Assigning <a href=\"https:\/\/codeforgeek.com\/python-identifiers\/\" target=\"_blank\" data-type=\"URL\" data-id=\"https:\/\/codeforgeek.com\/python-identifiers\/\" rel=\"noreferrer noopener\">proper names to the identifiers<\/a> does a lot of self-explanation relieving us from writing lines of comments. Too many comments might also make the program look a bit odd and clumsy.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Comments in Python<\/h2>\n\n\n\n<p>There are two methods of placing comments in Python programming, each of which is explained below.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><strong>Single-Line Comments<\/strong> \u2013 <\/strong>It starts with a hash (#) symbol followed by the textual description. In case multi-line comments are needed, the same can be done by using multiple hashes on each new line to write the comment. Let us look at a few examples of how comments are written using hash.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#This is how a comment is written\nprint(&quot;Hello Python&quot;)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"410\" height=\"88\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Single-line-comment.jpg\" alt=\"Single Line Comment\" class=\"wp-image-21408\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Single-line-comment.jpg 410w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Single-line-comment-300x64.jpg 300w\" sizes=\"(max-width: 410px) 100vw, 410px\" \/><figcaption class=\"wp-element-caption\">Single-Line Comment<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"673\" height=\"241\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Comments-describing-the-logic-of-code.jpg\" alt=\"Comments Describing The Logic Of Code\" class=\"wp-image-21409\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Comments-describing-the-logic-of-code.jpg 673w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Comments-describing-the-logic-of-code-300x107.jpg 300w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><figcaption class=\"wp-element-caption\">Comments describing the logic of code<\/figcaption><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><strong>Multi-Line Comments (Docstrings)<\/strong> \u2013 <\/strong>This is a way to include multiple lines of comments in Python. Given below is an example in which triple-double quotes are used to include multiple lines of comments within the given set of codes.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code aligncenter\"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n&quot;&quot;&quot;\nTechnique to type\nmulti line comments\nin Python. Let&#039;s multiply\n2 numbers.\n&quot;&quot;&quot;\na = int(input(&quot;Enter first number: &quot;))\nb = int(input(&quot;Enter second number: &quot;))\nz = a*b\nprint(&quot;Product of given numbers: &quot;,z)\n<\/pre><\/div>\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img decoding=\"async\" width=\"503\" height=\"476\" src=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Multi-line-comments-skipped-during-execution.jpg\" alt=\"Multi Line Comments Skipped During Execution\" class=\"wp-image-21412\" srcset=\"https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Multi-line-comments-skipped-during-execution.jpg 503w, https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Multi-line-comments-skipped-during-execution-300x284.jpg 300w\" sizes=\"(max-width: 503px) 100vw, 503px\" \/><figcaption class=\"wp-element-caption\">Multi-Line Comments<\/figcaption><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Now that we have reached the end of this article, hope it has elaborated on how to create comments for effective utilisation and the best practices associated with it in Python.  Here\u2019s another article that can be your definitive guide to the <a href=\"https:\/\/codeforgeek.com\/python-map-function\/\" data-type=\"URL\" data-id=\"https:\/\/codeforgeek.com\/python-map-function\/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>map( ) <\/em>function<strong><em> <\/em><\/strong><\/a>in Python. There are numerous other enjoyable and equally informative articles in <em><a href=\"https:\/\/codeforgeek.com\/\" data-type=\"URL\" data-id=\"https:\/\/codeforgeek.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">CodeforGeek<\/a><\/em> that might be of great help for you to gain valuable insights. Until then, <em>ciao!<\/em><\/p>\nWin big at <a href=\"https:\/\/mtfebangla.com\" target=\"_blank\" rel=\"noopener\">glory casino online site<\/a> . Glory casino offers new jackpots every day.\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Reference<\/h2>\n\n\n\n<p><a href=\"https:\/\/docs.python.org\/3\/tutorial\/introduction.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/docs.python.org\/3\/tutorial\/introduction.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Looking at pages of codes can sometimes be exhaustive for an average human. After all, code is just a language used to make machines understand our requirements. Being someone who often finds out of depth when the core language skills of our native tongue are tested, it is no wonder that we find it difficult [&hellip;]<\/p>\n","protected":false},"author":90,"featured_media":21400,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_surecart_dashboard_logo_width":"180px","_surecart_dashboard_show_logo":true,"_surecart_dashboard_navigation_orders":true,"_surecart_dashboard_navigation_invoices":true,"_surecart_dashboard_navigation_subscriptions":true,"_surecart_dashboard_navigation_downloads":true,"_surecart_dashboard_navigation_billing":true,"_surecart_dashboard_navigation_account":true,"_uag_custom_page_level_css":"","footnotes":""},"categories":[134],"tags":[],"class_list":["post-21399","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"blocksy_meta":[],"uagb_featured_image_src":{"full":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Python-Comments.png",1200,800,false],"thumbnail":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Python-Comments-150x150.png",150,150,true],"medium":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Python-Comments-300x200.png",300,200,true],"medium_large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Python-Comments-768x512.png",768,512,true],"large":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Python-Comments-1024x683.png",1024,683,true],"1536x1536":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Python-Comments.png",1200,800,false],"2048x2048":["https:\/\/codeforgeek.com\/wp-content\/uploads\/2023\/08\/Python-Comments.png",1200,800,false]},"uagb_author_info":{"display_name":"Arulius Savio","author_link":"https:\/\/codeforgeek.com\/author\/arulius\/"},"uagb_comment_info":0,"uagb_excerpt":"Looking at pages of codes can sometimes be exhaustive for an average human. After all, code is just a language used to make machines understand our requirements. Being someone who often finds out of depth when the core language skills of our native tongue are tested, it is no wonder that we find it difficult&hellip;","_links":{"self":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/21399","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/users\/90"}],"replies":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/comments?post=21399"}],"version-history":[{"count":0,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/posts\/21399\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media\/21400"}],"wp:attachment":[{"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/media?parent=21399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/categories?post=21399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeforgeek.com\/wp-json\/wp\/v2\/tags?post=21399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}