

{"id":6861,"date":"2018-01-31T11:07:24","date_gmt":"2018-01-31T11:07:24","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6861"},"modified":"2026-04-13T11:37:46","modified_gmt":"2026-04-13T06:07:46","slug":"python-comment","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-comment\/","title":{"rendered":"Python Comment, Indentation and Python Statement"},"content":{"rendered":"<p>In this Python tutorial, we will review basic syntax- Python Comment, Python indentation, and a Python statement with their subtypes, syntax, and examples.<\/p>\n<p>So, let&#8217;s start learning. <strong>Do check the Popular Python Interview Questions from this topic at the end.<\/strong><\/p>\n<h3>Python Statement<\/h3>\n<p><span style=\"font-size: 16px\">The Python interpreter deals with statements. The following is a statement in Python.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a*=3<\/pre>\n<h4>1. Multiline Python Statement<\/h4>\n<p>In Python, every statement ends with a newline character. But like we have seen, it is possible to span a statement over multiple lines.<\/p>\n<p>We do this using the \u2018\\\u2019 character.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=\\\r\n\u00a0\u00a0\u00a0 10\\\r\n\u00a0\u00a0\u00a0 +20\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">30<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; \"Hello\\\r\nhi\"<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\"><strong>&#8216;Hellohi&#8217;<\/strong><\/div>\n<p>But you can also use a set of parentheses for this.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 10+\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 20)\r\n&gt;&gt;&gt; a<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">30<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; type(a)\r\n&lt;class 'int'&gt;<\/pre>\n<h4>2. Multiple Python Statements in One Line<\/h4>\n<p>You can easily put multiple statements in Python on one line.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; a=7; print(a)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">7<\/div>\n<p>You can also do this to an if-statement.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; if 2&gt;1: print(\"2\")<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<h4>3. Strings Python Statements<\/h4>\n<p>To declare strings in Python, you may use single or double quotes.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; \"Hello 'user'\"<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8220;Hello &#8216;user'&#8221;<\/div>\n<p>If you use double quotes outside, use single quotes wherever you need to use a quote inside.<\/p>\n<h4>4. Blank Lines Python Statements<\/h4>\n<p>The interpreter simply ignores blank lines in Python.<\/p>\n<h3>Python Indentation<\/h3>\n<p>Unlike C++ or <strong>Java<\/strong>, Python does not use curly braces for indentation.<\/p>\n<p>Instead, Python mandates indentation. At this point, our inner monsters are laughing at the lazy programmers around us.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; if 2&gt;1:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"2\")<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">2<\/div>\n<p>There are no strict rules on what kind of Python indentation you use. But it must be consistent throughout the block.<\/p>\n<p>Although four whitespaces are usually preferred, and tabs are discouraged.<\/p>\n<p>Let\u2019s take an example with an inconsistent indentation in Python.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; if 2&gt;1:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 print(\"1\")\r\n\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0  print(\"2\")<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">SyntaxError: unexpected indent<\/div>\n<h3>Python Comment<\/h3>\n<p>Comments in Python are the lines that are ignored by Python while executing the program. Comments are notes for humans; Python skips over them. They explain \u201cwhy\u201d something happens, not \u201cwhat\u201d the code plainly shows.<\/p>\n<ul>\n<li>They make the code easy to read.<\/li>\n<li>It helps in understanding what work the code is doing.<\/li>\n<li>It makes the complex part of the code easy to understand.<\/li>\n<\/ul>\n<p>In C++, we have \/\/ for single-lined comments, and \/* \u2026 *\/ for multiple-lined comments. Here, we only have a single-line Python comment.<\/p>\n<p>To declare a Python comment, use the octothorpe (hash) (#).<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; #This is a comment\r\n&gt;&gt;&gt;<\/pre>\n<h4>1. Multiline Python Comment<\/h4>\n<p>To have a multiline Python comment in your code, you must use a hash at the beginning of every line of your comment in python.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; #Line 1 of comment\r\n&gt;&gt;&gt; #Line 2 of comment\r\n&gt;&gt;&gt; #Line 3 of comment<\/pre>\n<p>You can also use triple quotes (\u2018\u2019\u2019 \u2018\u2019\u2019 or \u201c\u201d\u201d \u201c\u201d\u201d) for this purpose.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; \"\"\"This comment\r\nis spanned across\r\nmultiple lines\"\"\"<\/pre>\n<p>&#8216;This comment\\nis spanned across\\nmultiple lines&#8217;<\/p>\n<p>This gives us an output because we type it in the shell. When you create a file and write this in that, there is no output.<\/p>\n<p>While triple quotes are generally used for multiline python comment, we can conveniently use them for Python comments as well.<\/p>\n<p>Triple quotes will also preserve formatting.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; print(\"\"\"Hello\r\nHi\"\"\")<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Hello<br \/>\nHi<\/div>\n<h4>2. Docstrings Python Comment<\/h4>\n<p>A docstring is a documentation <strong>string in Python<\/strong>. It is the first statement in a module, function, class, or <strong>method in Python<\/strong>.<\/p>\n<p>In this, you will learn what a Python function\/class does.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def sayhi():\r\n\t\"\"\"\r\n\tThis function prints Hi\r\n\t\"\"\"\r\n\tprint(\"Hi\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n&gt;&gt;&gt; sayhi()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<p>Hi<br \/>\nTo check a function\u2019s docstring, use its __doc__ attribute.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def sayhi():\r\n\t\"\"\"\r\n\tThis function prints Hi\r\n\t\"\"\"\r\n\tprint(\"Hi\") \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n&gt;&gt;&gt; sayhi.__doc__<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;\\n\\tThis function prints Hi\\n\\t&#8217;<\/div>\n<p>The interpreter is unable to get the docstring to a function if it isn\u2019t the first thing in the <strong>python function<\/strong>.<\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; def sayhi():\r\n\tprint(\"Hi\")\r\n\t\"\"\"\r\n\tThis function prints Hi\r\n\t\"\"\" \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n&gt;&gt;&gt; sayhi.__doc__\r\n&gt;&gt;&gt;<\/pre>\n<h3>Python Interview Questions on Python Indentation, Comment and Statement<\/h3>\n<p>1. What are the various types of Python Statements?<\/p>\n<p>2. How to write comments in Python?<\/p>\n<p>3. What is the use of Hash # in Python<\/p>\n<p>4. Why do we need proper indentation in Python?<\/p>\n<p>5. Write a code explaining the Docstring Python Comment.<\/p>\n<h3>Conclusion<\/h3>\n<p>These three building blocks in Python\u2014statements, indentation, and comments\u2014look small, yet they decide whether your Python script reads like a children\u2019s story or a jumbled puzzle. By mastering them now, you set a solid base for every advanced topic to come, from object-oriented programming to data analysis in Python. Keep your instructions clear, align your blocks with care, and speak to future readers through concise comments. Your code will not just run; it will shine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python tutorial, we will review basic syntax- Python Comment, Python indentation, and a Python statement with their subtypes, syntax, and examples. So, let&#8217;s start learning. Do check the Popular Python Interview Questions&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":84787,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[2017,2681,6679,8936,10432,10592,10853,15094,15099],"class_list":["post-6861","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-blank-python-statements","tag-comment-in-python","tag-indentation-in-python","tag-multiline-python-statement","tag-python-comment","tag-python-indentation","tag-python-statements","tag-types-of-python-comment","tag-types-of-python-statement"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Comment, Indentation and Python Statement - DataFlair<\/title>\n<meta name=\"description\" content=\"By mastering Python Comment, Indentation &amp; Python statement you set a solid base for every advanced topic to come. Let&#039;s start learning.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-comment\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Comment, Indentation and Python Statement - DataFlair\" \/>\n<meta property=\"og:description\" content=\"By mastering Python Comment, Indentation &amp; Python statement you set a solid base for every advanced topic to come. Let&#039;s start learning.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-comment\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-31T11:07:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-13T06:07:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Comment-Python-Indentation-and-Python-Statement.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Comment, Indentation and Python Statement - DataFlair","description":"By mastering Python Comment, Indentation & Python statement you set a solid base for every advanced topic to come. Let's start learning.","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:\/\/data-flair.training\/blogs\/python-comment\/","og_locale":"en_US","og_type":"article","og_title":"Python Comment, Indentation and Python Statement - DataFlair","og_description":"By mastering Python Comment, Indentation & Python statement you set a solid base for every advanced topic to come. Let's start learning.","og_url":"https:\/\/data-flair.training\/blogs\/python-comment\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-31T11:07:24+00:00","article_modified_time":"2026-04-13T06:07:46+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Comment-Python-Indentation-and-Python-Statement.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-comment\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-comment\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Comment, Indentation and Python Statement","datePublished":"2018-01-31T11:07:24+00:00","dateModified":"2026-04-13T06:07:46+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-comment\/"},"wordCount":660,"commentCount":24,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-comment\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Comment-Python-Indentation-and-Python-Statement.jpg","keywords":["Blank Python Statements","comment in python","indentation in python","Multiline python Statement","Python Comment","Python indentation","python statements","Types of Python Comment","types of Python Statement"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-comment\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-comment\/","url":"https:\/\/data-flair.training\/blogs\/python-comment\/","name":"Python Comment, Indentation and Python Statement - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-comment\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-comment\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Comment-Python-Indentation-and-Python-Statement.jpg","datePublished":"2018-01-31T11:07:24+00:00","dateModified":"2026-04-13T06:07:46+00:00","description":"By mastering Python Comment, Indentation & Python statement you set a solid base for every advanced topic to come. Let's start learning.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-comment\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-comment\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-comment\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Comment-Python-Indentation-and-Python-Statement.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Python-Comment-Python-Indentation-and-Python-Statement.jpg","width":1200,"height":628,"caption":"Python Comment, Python Indentation and Python Statement"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-comment\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Comment, Indentation and Python Statement"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6861"}],"version-history":[{"count":16,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6861\/revisions"}],"predecessor-version":[{"id":147570,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6861\/revisions\/147570"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/84787"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}