{"id":130228,"date":"2023-05-10T16:01:58","date_gmt":"2023-05-10T10:31:58","guid":{"rendered":"https:\/\/www.vskills.in\/certification\/tutorial\/?page_id=130228"},"modified":"2024-04-12T14:33:57","modified_gmt":"2024-04-12T09:03:57","slug":"the-if-statement-3","status":"publish","type":"page","link":"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/","title":{"rendered":"The if statement"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\"><strong>The if statement<\/strong><\/h4>\n\n\n\n<p>The if statement in Python is a conditional statement that allows you to execute different blocks of code depending on whether a certain condition is true or false. The syntax of the if statement is as follows:<\/p>\n\n\n\n<p>sql<\/p>\n\n\n\n<p>if condition:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;# code to be executed if the condition is true<\/p>\n\n\n\n<p>If the condition is true, then the code inside the if block will be executed. If the condition is false, then the code inside the block will be skipped and the program will continue to the next statement.<\/p>\n\n\n\n<p>The if statement can also be extended using the elif and else clauses. The elif clause allows you to check for multiple conditions, while the else clause allows you to execute code if none of the previous conditions were true. The syntax for using elif and else is as follows:<\/p>\n\n\n\n<p>vbnet<\/p>\n\n\n\n<p>if condition1:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;# code to be executed if condition1 is true<\/p>\n\n\n\n<p>elif condition2:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;# code to be executed if condition2 is true and condition1 is false<\/p>\n\n\n\n<p>else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;# code to be executed if both condition1 and condition2 are false<\/p>\n\n\n\n<p>It is important to note that the code inside the if block and its related elif and else blocks must be indented properly. The standard indentation in Python is four spaces.<\/p>\n\n\n\n<p>Here is an example of using the if statement to check if a number is even or odd:<\/p>\n\n\n\n<p>bash<\/p>\n\n\n\n<p>x = 5<\/p>\n\n\n\n<p>if x % 2 == 0:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;print(x, &#8220;is even&#8221;)<\/p>\n\n\n\n<p>else:<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;print(x, &#8220;is odd&#8221;) This will output &#8220;5 is odd&#8221; since the condition x % 2 == 0 is false for the value of x.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The if statement The if statement in Python is a conditional statement that allows you to execute different blocks of code depending on whether a certain condition is true or false. The syntax of the if statement is as follows: sql if condition: &nbsp;&nbsp;&nbsp;&nbsp;# code to be executed if the condition is true If the&#8230;<\/p>\n","protected":false},"author":23,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[252],"tags":[],"class_list":["post-130228","page","type-page","status-publish","hentry","category-python-developer"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>The if statement - Tutorial<\/title>\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.vskills.in\/certification\/tutorial\/the-if-statement-3\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"The if statement - Tutorial\" \/>\n<meta property=\"og:description\" content=\"The if statement The if statement in Python is a conditional statement that allows you to execute different blocks of code depending on whether a certain condition is true or false. The syntax of the if statement is as follows: sql if condition: &nbsp;&nbsp;&nbsp;&nbsp;# code to be executed if the condition is true If the...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/vskills.in\/\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-12T09:03:57+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/\",\"name\":\"The if statement - Tutorial\",\"isPartOf\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\"},\"datePublished\":\"2023-05-10T10:31:58+00:00\",\"dateModified\":\"2024-04-12T09:03:57+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"The if statement\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#website\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"name\":\"Tutorial\",\"description\":\"Vskills - A initiative in elearning and certification\",\"publisher\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#organization\",\"name\":\"Vskills\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"contentUrl\":\"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg\",\"width\":73,\"height\":55,\"caption\":\"Vskills\"},\"image\":{\"@id\":\"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/vskills.in\/\",\"https:\/\/x.com\/vskills_in\",\"https:\/\/www.linkedin.com\/company-beta\/1371554\/\",\"https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"The if statement - Tutorial","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.vskills.in\/certification\/tutorial\/the-if-statement-3\/","og_locale":"en_US","og_type":"article","og_title":"The if statement - Tutorial","og_description":"The if statement The if statement in Python is a conditional statement that allows you to execute different blocks of code depending on whether a certain condition is true or false. The syntax of the if statement is as follows: sql if condition: &nbsp;&nbsp;&nbsp;&nbsp;# code to be executed if the condition is true If the...","og_url":"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/","og_site_name":"Tutorial","article_publisher":"https:\/\/www.facebook.com\/vskills.in\/","article_modified_time":"2024-04-12T09:03:57+00:00","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/","name":"The if statement - Tutorial","isPartOf":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website"},"datePublished":"2023-05-10T10:31:58+00:00","dateModified":"2024-04-12T09:03:57+00:00","breadcrumb":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/the-if-statement-3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vskills.in\/certification\/tutorial\/"},{"@type":"ListItem","position":2,"name":"The if statement"}]},{"@type":"WebSite","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#website","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","name":"Tutorial","description":"Vskills - A initiative in elearning and certification","publisher":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.vskills.in\/certification\/tutorial\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#organization","name":"Vskills","url":"https:\/\/www.vskills.in\/certification\/tutorial\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/","url":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","contentUrl":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-content\/uploads\/2017\/07\/vskills-min-logo.jpg","width":73,"height":55,"caption":"Vskills"},"image":{"@id":"https:\/\/www.vskills.in\/certification\/tutorial\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/vskills.in\/","https:\/\/x.com\/vskills_in","https:\/\/www.linkedin.com\/company-beta\/1371554\/","https:\/\/www.youtube.com\/channel\/UCMWnscxPwRF_PqXo9B7q_Tw"]}]}},"_links":{"self":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/130228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/users\/23"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/comments?post=130228"}],"version-history":[{"count":3,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/130228\/revisions"}],"predecessor-version":[{"id":130235,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/pages\/130228\/revisions\/130235"}],"wp:attachment":[{"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/media?parent=130228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/categories?post=130228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vskills.in\/certification\/tutorial\/wp-json\/wp\/v2\/tags?post=130228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}