{"id":389,"date":"2024-07-15T11:59:40","date_gmt":"2024-07-15T06:59:40","guid":{"rendered":"https:\/\/augurytech.co.uk\/courses\/?p=389"},"modified":"2024-10-05T09:06:19","modified_gmt":"2024-10-05T04:06:19","slug":"python-if-else-statement","status":"publish","type":"post","link":"https:\/\/augurytech.co.uk\/courses\/python\/python-if-else-statement\/","title":{"rendered":"Python: if else Statement"},"content":{"rendered":"\n<p>The <strong>if else<\/strong> statement in Python is used to execute a block of code based on a condition. It allows you to perform different actions depending on whether a specific condition is <strong>true or false<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>If<\/strong> statement<\/li>\n\n\n\n<li><strong>If else<\/strong> statement<\/li>\n<\/ul>\n\n\n\n<p>The &#8221; <strong>if<\/strong> &#8221; statement is used to execute a block of code if a condition is true. On the other hand, the &#8221; <strong>if else <\/strong>&#8221; statement is used to execute one block of code if the condition is true, and another block means the <strong>else<\/strong> statement if the condition is false. This allows for different actions to be taken depending on the result of the condition.<\/p>\n\n\n\n<p>Remember to pay attention to indentation while writing these statements. Proper indentation ensures that the correct code blocks are associated with each condition.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\" style=\"margin-bottom:var(--wp--preset--spacing--20);padding-top:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--30);font-size:clamp(1.125rem, 1.125rem + ((1vw - 0.2rem) * 0.612), 1.5rem);\"><code><strong>x = 10\nif x &gt; 5:\n    print(\"x is greater than 5\")\nelse:\n    print(\"x is less than or equal to 5\")<\/strong><\/code><\/pre>\n\n\n\n<p>In this example, if the condition &#8221; x &gt; 5 &#8221; is true, the code inside the &#8221; if &#8221; block is executed. Otherwise, the code inside the &#8221; else &#8221; block is executed. This is a fundamental concept in programming and is used extensively to control the flow of a program based on different conditions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The if else statement in Python is used to execute a block of code based on a condition. It allows you to perform different actions depending on whether a specific condition is true or false. The &#8221; if &#8221; statement is used to execute a block of code if a condition is true. On the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-python","format":"standard","meta":{"_seopress_robots_primary_cat":"","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[5],"tags":[],"class_list":{"0":"post-389","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python"},"_links":{"self":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/comments?post=389"}],"version-history":[{"count":8,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":404,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/389\/revisions\/404"}],"wp:attachment":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/media?parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/categories?post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/tags?post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}