{"id":57,"date":"2026-03-01T15:28:02","date_gmt":"2026-03-01T10:28:02","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=57"},"modified":"2026-03-13T09:31:42","modified_gmt":"2026-03-13T04:31:42","slug":"if-else-elif","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/","title":{"rendered":"\u00a0If, Else, Elif"},"content":{"rendered":"\n<p>Conditional statements allow your program to make decisions. In Python, we use <strong>if, else, and elif<\/strong> to execute different blocks of code based on conditions.<\/p>\n\n\n\n<p>These statements help control the flow of a program.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>1. IF STATEMENT<\/strong><\/h1>\n\n\n\n<p>The <strong>if<\/strong> statement checks a condition.<br>If the condition is <strong>True<\/strong>, the code inside the block runs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax:<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">if condition:<br>    # code to execute<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example:<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">age = 18if age &gt;= 18:<br>    print(\"You are eligible to vote.\")<\/pre>\n\n\n\n<p>If the condition is true, the message will be printed.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>2. ELSE STATEMENT<\/strong><\/h1>\n\n\n\n<p>The <strong>else<\/strong> statement runs when the condition in the if statement is <strong>False<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax:<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">if condition:<br>    # code if true<br>else:<br>    # code if false<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example:<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">age = 16if age &gt;= 18:<br>    print(\"You are eligible to vote.\")<br>else:<br>    print(\"You are not eligible to vote.\")<\/pre>\n\n\n\n<p>Since the condition is false, the else block runs.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>3. ELIF STATEMENT<\/strong><\/h1>\n\n\n\n<p>The <strong>elif<\/strong> (else if) statement checks multiple conditions.<br>It is used when you have more than two possible outcomes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Syntax:<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">if condition1:<br>    # code<br>elif condition2:<br>    # code<br>else:<br>    # code<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example:<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">marks = 75if marks &gt;= 90:<br>    print(\"Grade A\")<br>elif marks &gt;= 80:<br>    print(\"Grade B\")<br>elif marks &gt;= 70:<br>    print(\"Grade C\")<br>else:<br>    print(\"Fail\")<\/pre>\n\n\n\n<p>The program checks conditions one by one.<br>When a true condition is found, it executes that block and stops checking further conditions.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>IMPORTANT RULES<\/strong><\/h1>\n\n\n\n<p>\u2022 Indentation is very important in Python.<br>\u2022 Use colon (:) after if, elif, and else.<br>\u2022 Only one else block is allowed.<br>\u2022 You can use multiple elif blocks.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>NESTED IF STATEMENT<\/strong><\/h1>\n\n\n\n<p>You can place an if statement inside another if statement.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example:<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">age = 20<br>has_id = Trueif age &gt;= 18:<br>    if has_id:<br>        print(\"You can enter.\")<br>    else:<br>        print(\"You need an ID.\")<br>else:<br>    print(\"You are underage.\")<\/pre>\n\n\n\n<h1 class=\"wp-block-heading\"><strong>WHY CONDITIONAL STATEMENTS ARE IMPORTANT<\/strong><\/h1>\n\n\n\n<p>\u2022 They help programs make decisions<br>\u2022 They control program flow<br>\u2022 They allow logical problem solving<\/p>\n\n\n\n<p>Understanding <strong>if, else, and elif<\/strong> is essential for building real-world Python applications.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">PYTHON FUNDAMENTALS (PYF) > Control Flow > If, Else, Elif<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773376200276\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":16,"template":"","class_list":["post-57","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>\u00a0If, Else, Elif - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python conditional statements using if, else, and elif to control program flow, make decisions, and build logical programs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u00a0If, Else, Elif - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python conditional statements using if, else, and elif to control program flow, make decisions, and build logical programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-13T04:31:42+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/if-else-elif\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/if-else-elif\\\/\",\"name\":\"\u00a0If, Else, Elif - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-01T10:28:02+00:00\",\"dateModified\":\"2026-03-13T04:31:42+00:00\",\"description\":\"Learn Python conditional statements using if, else, and elif to control program flow, make decisions, and build logical programs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/if-else-elif\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/if-else-elif\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/if-else-elif\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PYTHON FUNDAMENTALS (PYF) > Control Flow > If, Else, Elif\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u00a0If, Else, Elif - One Language. Endless Possibilities","description":"Learn Python conditional statements using if, else, and elif to control program flow, make decisions, and build logical programs.","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:\/\/gigz.pk\/python\/lesson\/if-else-elif\/","og_locale":"en_US","og_type":"article","og_title":"\u00a0If, Else, Elif - One Language. Endless Possibilities","og_description":"Learn Python conditional statements using if, else, and elif to control program flow, make decisions, and build logical programs.","og_url":"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-13T04:31:42+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/","url":"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/","name":"\u00a0If, Else, Elif - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-01T10:28:02+00:00","dateModified":"2026-03-13T04:31:42+00:00","description":"Learn Python conditional statements using if, else, and elif to control program flow, make decisions, and build logical programs.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/if-else-elif\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"PYTHON FUNDAMENTALS (PYF) > Control Flow > If, Else, Elif"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}