{"id":113293,"date":"2025-11-19T11:33:35","date_gmt":"2025-11-19T06:03:35","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/?page_id=113293"},"modified":"2025-11-17T10:40:09","modified_gmt":"2025-11-17T05:10:09","slug":"python-comments-and-indentation","status":"publish","type":"page","link":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/","title":{"rendered":"Python Comments and Indentation"},"content":{"rendered":"\n<h1 id=\"python-comments-and-indentation\">Python Comments and Indentation<\/h1>\n\n<p>\n  <em>\"Code is read much more often than it is written.\"<\/em> - <strong>Guido van Rossum<\/strong> (Creator of Python)\n<\/p>\n<p>\n  To write professional Python code, you must master two critical tools: <strong>Comments<\/strong> (which explain logic) and <strong>Indentation<\/strong> (which defines structure).\n<\/p>\n\n<h2 id=\"python-comments\">Python Comments<\/h2>\n<p>\n  A <strong>comment<\/strong> is a text note written directly in your code that the computer ignores. It allows you to document your logic without affecting the program execution.\n<\/p>\n\n<h3 id=\"1-single-line-comments\">1. Single-Line Comments<\/h3>\n<p>\n  A single-line comment is a note that occupies only one line of text. It is used to explain the code immediately following it.\n<\/p>\n<p>\n  <strong>Syntax:<\/strong> Type the hash symbol (<code>#<\/code>). Python ignores everything after this symbol on that specific line.\n<\/p>\n<div class=\"code-example\">\n  <pre><code># This is a single-line comment\nprint(\"Hello World\")<\/code><\/pre>\n<\/div>\n\n<h3 id=\"2-inline-comments\">2. Inline Comments<\/h3>\n<p>\n An inline comment is a short note placed on the exact same line as a code statement.\n<\/p>\n<p>\n  <strong>Syntax:<\/strong> Type the code statement, add at least two spaces, then type the hash symbol (<code>#<\/code>) followed by your note.\n<\/p>\n<div class=\"code-example\">\n  <pre><code>x = 5  # This is an inline comment<\/code><\/pre>\n<\/div>\n\n<h4 id=\"exercise-1-annotating-logic\">Exercise 1: Annotating Logic<\/h4>\n<p>\n  The code below calculates a price, but the context is missing. Add two comments:\n<\/p>\n<ol>\n  <li>A <strong>Single-Line Comment<\/strong> above the math explaining the business rule (\"Apply Holiday Discount\").<\/li>\n  <li>An <strong>Inline Comment<\/strong> next to the variable explaining the value (\"15% rate\").<\/li>\n<\/ol>\n\n<div class=\"code-editor-container\">\n  <div id=\"editor-1\" class=\"python-code-editor\">\n# Add single-line comment here\nrate = 0.15  # Add inline comment here\nprice = 200\nfinal_price = price - (price * rate)\nprint(final_price)\n  <\/div>\n  <div class=\"button-container\">\n    <button class=\"button button-run\" onclick=\"runPythonCode('editor-1', 'output-1')\">Run Code<\/button>\n    <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-1', this)\">Show Example<\/button>\n  <\/div>\n\n  <div id=\"solution-1\" class=\"code-solution\">\n    <pre><code># Apply Holiday Discount\nrate = 0.15  # 15% rate\nprice = 200\nfinal_price = price - (price * rate)\nprint(final_price)<\/code><\/pre>\n  <\/div>\n\n  <label for=\"output-1\" class=\"output-label\">Output:<\/label>\n  <pre id=\"output-1\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<h3 id=\"3-docstrings-documentation-strings\">3. Docstrings (Documentation Strings)<\/h3>\n<p>\n A Docstring is a multi-line string used to document a specific segment of code, such as a function or a class. Unlike standard comments, Docstrings are retained by Python at runtime.\n<\/p>\n<p>\n  <strong>Syntax:<\/strong> Enclose the text in triple quotes (<code>\"\"\"<\/code>). This must be the <strong>very first line<\/strong> inside the function.\n<\/p>\n\n<h4 id=\"exercise-2-writing-a-docstring\">Exercise 2: Writing a Docstring<\/h4>\n<p>\n  The function below has no documentation. Wrap the description text in triple quotes to create a valid Docstring.\n<\/p>\n\n<div class=\"code-editor-container\">\n  <div id=\"editor-2\" class=\"python-code-editor\">\ndef calculate_area(radius):\n    Calculates the area of a circle.\n    Takes radius as an argument.\n    Returns the area value.\n    \n    pi = 3.14\n    return pi * (radius ** 2)\n\nprint(calculate_area(5))\n  <\/div>\n  <div class=\"button-container\">\n    <button class=\"button button-run\" onclick=\"runPythonCode('editor-2', 'output-2')\">Run Code<\/button>\n    <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-2', this)\">Show Example<\/button>\n  <\/div>\n\n  <div id=\"solution-2\" class=\"code-solution\">\n    <pre><code>def calculate_area(radius):\n    \"\"\"\n    Calculates the area of a circle.\n    Takes radius as an argument.\n    Returns the area value.\n    \"\"\"\n    pi = 3.14\n    return pi * (radius ** 2)\n\nprint(calculate_area(5))<\/code><\/pre>\n  <\/div>\n\n  <label for=\"output-2\" class=\"output-label\">Output:<\/label>\n  <pre id=\"output-2\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n\n\n\n<h2 id=\"indentation-and-structure\">Indentation and Structure<\/h2>\n<p>\n  In many programming languages, curly braces <code>{}<\/code> are used to group code. Python uses <strong>Indentation<\/strong>.\n<\/p>\n\n<h3 id=\"1-indentation\">1. Indentation<\/h3>\n<p>\n  Indentation is the empty whitespace at the beginning of a line of code.  It tells Python which lines of code belong to a specific block.\n\n<\/p>\n\n<p>\n  <strong>Syntax Rule:<\/strong> Use <strong>4 spaces<\/strong> per indentation level.\n<\/p>\n\n<div style=\"text-align: center;\">\n    <img decoding=\"async\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-indentation.png\" \n         alt=\"Indentation in Python\" \n         style=\"max-width: 100%; height: auto;\">\n<\/div>\n\n\n<h3 id=\"2-blocks-and-scope\">2. Blocks and Scope<\/h3>\n<p>\n A \"Block\" is a group of statements that execute together. \"Scope\" refers to the context in which that block is valid.\n<\/p>\n<p>\n  <strong>Syntax Rule:<\/strong> Any statement ending in a colon (<code>:<\/code>) starts a new block. All subsequent lines indented by 4 spaces belong to that block.\n<\/p>\n\n<div style=\"text-align: center;\">\n    <img decoding=\"async\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-blocks.png\" \n         alt=\"Indentation in Python - Code Blocks Example\" \n         style=\"max-width: 100%; height: auto;\">\n<\/div>\n\n<h4 id=\"exercise-3-defining-a-block\">Exercise 3: Defining a Block<\/h4>\n<p>\n  <strong>The Logic:<\/strong> The \"Access Granted\" message should only print if the password is correct. It must be <em>inside<\/em> the <code>if<\/code> block.\n<\/p>\n<p>\n  <strong>Task:<\/strong> Indent the print statement by 4 spaces to move it inside the block.\n<\/p>\n\n<div class=\"code-editor-container\">\n  <div id=\"editor-3\" class=\"python-code-editor\">\npassword = \"wrong_password\"\n\nif password == \"secret_code\":\n# TODO: Indent 4 spaces to move inside the block\nprint(\"Access Granted!\")\n\nprint(\"Login attempt finished.\")\n  <\/div>\n  <div class=\"button-container\">\n    <button class=\"button button-run\" onclick=\"runPythonCode('editor-3', 'output-3')\">Run Code<\/button>\n    <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-3', this)\">Show Example<\/button>\n  <\/div>\n\n  <div id=\"solution-3\" class=\"code-solution\">\n    <pre><code>password = \"wrong_password\"\n\nif password == \"secret_code\":\n    # Inside the block (Indented)\n    print(\"Access Granted!\")\n\n# Outside the block (Un-indented)\nprint(\"Login attempt finished.\")<\/code><\/pre>\n  <\/div>\n\n  <label for=\"output-3\" class=\"output-label\">Output:<\/label>\n  <pre id=\"output-3\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<h3 id=\"3-nested-blocks\">3. Nested Blocks<\/h3>\n<p>\n Nesting is the practice of placing one code block inside another code block (e.g., an <code>if<\/code> statement inside a <code>for<\/code> loop).\n<\/p>\n<p>\n  <strong>Syntax Rule:<\/strong> Increase indentation by 4 spaces for every new block depth.\n<\/p>\n<ul>\n  <li><strong>Level 0 (0 spaces):<\/strong> Main program.<\/li>\n  <li><strong>Level 1 (4 spaces):<\/strong> Inside the first block.<\/li>\n  <li><strong>Level 2 (8 spaces):<\/strong> Inside the second (nested) block.<\/li>\n<\/ul>\n\n<div style=\"text-align: center;\">\n    <img decoding=\"async\" src=\"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/nested-blocks-python.png\" \n         alt=\"Nested Blocks in Python\" \n         style=\"max-width: 100%; height: auto;\">\n<\/div>\n\n<h4 id=\"exercise-4-structure-nested-logic\">Exercise 4: Structure Nested Logic<\/h4>\n<p>\n  We need to filter a list of temperatures. Organize the code structure using correct indentation:\n<\/p>\n<ol>\n  <li>The <code>if<\/code> statement must be inside the Loop (Level 1).<\/li>\n  <li>The <code>print<\/code> statement must be inside the If check (Level 2).<\/li>\n<\/ol>\n\n<div class=\"code-editor-container\">\n  <div id=\"editor-4\" class=\"python-code-editor\">\ntemps = [102, 98, 105, 99]\n\nfor t in temps:\n# TODO: Indent to Level 1 (4 spaces)\nif t > 100:\n# TODO: Indent to Level 2 (8 spaces)\nprint(f\"Warning: {t} is too high!\")\n  <\/div>\n  <div class=\"button-container\">\n    <button class=\"button button-run\" onclick=\"runPythonCode('editor-4', 'output-4')\">Run Code<\/button>\n    <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-4', this)\">Show Answer<\/button>\n  <\/div>\n\n  <div id=\"solution-4\" class=\"code-solution\">\n    <pre><code>temps = [102, 98, 105, 99]\n\nfor t in temps:\n    # Level 1: Inside the loop\n    if t > 100:\n        # Level 2: Inside the If\n        print(f\"Warning: {t} is too high!\")<\/code><\/pre>\n  <\/div>\n\n  <label for=\"output-4\" class=\"output-label\">Output:<\/label>\n  <pre id=\"output-4\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n\n<h2 id=\"best-practices-checklist\">Best Practices Checklist<\/h2>\n<p>Before writing production code, verify your style against these standards.<\/p>\n\n<table style=\"width: 100%; border-collapse: collapse; margin-bottom: 20px;\">\n  <tr style=\"background-color: #f4f4f4;\">\n    <th style=\"border: 1px solid #ddd; padding: 12px; text-align: left;\">Practice<\/th>\n    <th style=\"border: 1px solid #ddd; padding: 12px; text-align: left;\">Explanation<\/th>\n  <\/tr>\n  <tr>\n    <td style=\"border: 1px solid #ddd; padding: 12px;\"><strong>Explain \"Why\", not \"What\"<\/strong><\/td>\n    <td style=\"border: 1px solid #ddd; padding: 12px;\">Do not describe the syntax (the code shows that). Describe the business reason (why you are doing it).<\/td>\n  <\/tr>\n  <tr>\n    <td style=\"border: 1px solid #ddd; padding: 12px;\"><strong>Keep Comments Current<\/strong><\/td>\n    <td style=\"border: 1px solid #ddd; padding: 12px;\">If you change the code logic, you must update the comment immediately to avoid confusion.<\/td>\n  <\/tr>\n  <tr>\n    <td style=\"border: 1px solid #ddd; padding: 12px;\"><strong>Strict Indentation<\/strong><\/td>\n    <td style=\"border: 1px solid #ddd; padding: 12px;\">Always use 4 spaces. Do not mix tabs and spaces, as this causes errors in Python 3.<\/td>\n  <\/tr>\n<\/table>\n\n<h2 id=\"final-challenge-refactoring-code\">Final Challenge: Refactoring Code<\/h2>\n<p>\n  The code below is unreadable and lacks documentation.\n<\/p>\n<p><strong>Your Task:<\/strong><\/p>\n<ol>\n  <li>Add a Docstring explaining the function's purpose.<\/li>\n  <li>Indent the logic correctly inside the function and loop.<\/li>\n  <li>Add one comment explaining the business logic of the <code>if<\/code> check.<\/li>\n<\/ol>\n\n<div class=\"code-editor-container\">\n  <div id=\"editor-5\" class=\"python-code-editor\">\ndef process_numbers(data):\ntotal = 0\nfor num in data:\nif num > 0:\ntotal += num\nreturn total\n\nresult = process_numbers([10, -5, 20, -1])\nprint(f\"Sum of positives: {result}\")\n  <\/div>\n  <div class=\"button-container\">\n    <button class=\"button button-run\" onclick=\"runPythonCode('editor-5', 'output-5')\">Run Code<\/button>\n    <button class=\"button button-toggle\" onclick=\"toggleSolution('solution-5', this)\">Show Solution<\/button>\n  <\/div>\n\n  <div id=\"solution-5\" class=\"code-solution\">\n    <pre><code>def process_numbers(data):\n    \"\"\"\n    Calculates the sum of all positive numbers in a list.\n    \"\"\"\n    total = 0\n    for num in data:\n        # Business Logic: Only include positive numbers\n        if num > 0:\n            total += num\n    return total\n\nresult = process_numbers([10, -5, 20, -1])\nprint(f\"Sum of positives: {result}\")<\/code><\/pre>\n  <\/div>\n\n  <label for=\"output-5\" class=\"output-label\">Output:<\/label>\n  <pre id=\"output-5\" class=\"code-output\">Your output will appear here...<\/pre>\n<\/div>\n\n<div class=\"cta-final\">\n  <div class=\"cta-final-header\">\n    <span class=\"cta-final-trophy\">\ud83c\udfc6<\/span>\n    <h2 id=\"lesson-completed\">Lesson Completed<\/h2>\n  <\/div>\n\n  <p class=\"cta-final-intro\">\n    You now understand the definitions of Indentation and Scope, and how to use them to structure Python code.\n  <\/p>\n\n  <div class=\"cta-final-grid\">\n    <div class=\"cta-final-option\">\n      <div class=\"cta-final-option-header\">\n        <span>\ud83d\udcd8<\/span>\n        <h4 id=\"full-python-course\">Full Python Course<\/h4>\n      <\/div>\n      <p>Master Python with 11+ hours of content, 50+ exercises, and real-world projects.<\/p>\n      <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming?utm_source=blog\" class=\"cta-final-button-primary\">Enroll Now<\/a>\n    <\/div>\n\n    <div class=\"cta-final-option\" id=\"pt-next-lesson-container\">\n      <div class=\"cta-final-option-header\">\n        <span>\ud83d\udcdd<\/span>\n        <h4 id=\"next-lesson\">Next Lesson<\/h4>\n      <\/div>\n      <p id=\"pt-next-lesson-text\">Continue with the next lesson on Python Constants.<\/p>\n      <a href=\"#\" id=\"pt-next-lesson-button\" class=\"cta-final-button-secondary\">Next Lesson -><\/a>\n    <\/div>\n  <\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.<\/p>\n","protected":false},"author":41,"featured_media":113344,"parent":113156,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"templates\/python-tutorial.php","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796,36893],"class_list":["post-113293","page","type-page","status-publish","has-post-thumbnail","hentry","category-software","tag-python","tag-python-tutorial"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Comments and Indentation<\/title>\n<meta name=\"description\" content=\"Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Comments and Indentation\" \/>\n<meta property=\"og:description\" content=\"Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Python Comments and Indentation\",\"datePublished\":\"2025-11-19T06:03:35+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/\"},\"wordCount\":788,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-comments-indentation.webp\",\"keywords\":[\"python\",\"python-tutorial\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/\",\"name\":\"Python Comments and Indentation\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-comments-indentation.webp\",\"datePublished\":\"2025-11-19T06:03:35+00:00\",\"description\":\"Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-comments-indentation.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/11\\\/python-comments-indentation.webp\",\"width\":1408,\"height\":768,\"caption\":\"Python Comments and Indentation\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/python-comments-and-indentation\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Tutorial\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python Comments and Indentation\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Comments and Indentation","description":"Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.","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:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/","og_locale":"en_US","og_type":"article","og_title":"Python Comments and Indentation","og_description":"Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","og_image":[{"width":1408,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp","type":"image\/webp"}],"twitter_card":"summary_large_image","twitter_site":"@Great_Learning","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Python Comments and Indentation","datePublished":"2025-11-19T06:03:35+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/"},"wordCount":788,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp","keywords":["python","python-tutorial"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/","url":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/","name":"Python Comments and Indentation","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp","datePublished":"2025-11-19T06:03:35+00:00","description":"Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp","width":1408,"height":768,"caption":"Python Comments and Indentation"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/python\/python-comments-and-indentation\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python Tutorial","item":"https:\/\/www.mygreatlearning.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python Comments and Indentation"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/11\/python-comments-indentation-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Complete guide to Python comments and indentation. Practice single-line comments, docstrings, nested blocks, and code structure with interactive exercises.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=113293"}],"version-history":[{"count":16,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113293\/revisions"}],"predecessor-version":[{"id":113335,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113293\/revisions\/113335"}],"up":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/pages\/113156"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/113344"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=113293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=113293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=113293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}