{"id":16606,"date":"2021-09-08T12:21:07","date_gmt":"2021-09-08T06:51:07","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=16606"},"modified":"2022-04-19T18:08:57","modified_gmt":"2022-04-19T12:38:57","slug":"if-statement-true-python-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/","title":{"rendered":"If statement true Python | Example code"},"content":{"rendered":"\n<p>If statement concept works on Boolean true and false. If block codes will execute if the <strong>Boolean expression evaluates to TRUE<\/strong>. If the <a href=\"https:\/\/tutorial.eyehunts.com\/python\/true-false-python-booleans-represent\/\">Boolean expression<\/a> evaluates to <strong>FALSE <\/strong>then the code inside the block will not execute.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if expression:\n   code(...)<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Python example if the statement is a true<\/strong> <\/h2>\n\n\n\n<p>Simple example code. Try it at least twice, with different <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-input-function-string-integer-number\/\">inputs<\/a>. You will get an extra output result, depending on the input.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>weight = int(input(\"Enter suitcase weigh: \"))\n\nif weight &gt;= 50:\n    print(\"There is a $25 charge for luggage that heavy.\")\n\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"562\" height=\"155\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg?resize=562%2C155&#038;ssl=1\" alt=\"If statement true Python\" class=\"wp-image-19355\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>If statement concept works on Boolean true and false. If block codes will execute if the Boolean expression evaluates to TRUE. If the Boolean expression evaluates to FALSE then the code inside the block will not execute. Python example if the statement is a true Simple example code. Try it at least twice, with different&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">If statement true Python | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[37,181],"post_series":[],"class_list":["post-16606","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-conditions","tag-python-if"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>If statement true Python | Example code - EyeHunts<\/title>\n<meta name=\"description\" content=\"If statement concept works on Boolean true and false. If block codes will execute if the Boolean expression evaluates to TRUE. If the Boolean\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"If statement true Python | Example code - EyeHunts\" \/>\n<meta property=\"og:description\" content=\"If statement concept works on Boolean true and false. If block codes will execute if the Boolean expression evaluates to TRUE. If the Boolean\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-09-08T06:51:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-19T12:38:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/\",\"name\":\"If statement true Python | Example code - EyeHunts\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg\",\"datePublished\":\"2021-09-08T06:51:07+00:00\",\"dateModified\":\"2022-04-19T12:38:57+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"If statement concept works on Boolean true and false. If block codes will execute if the Boolean expression evaluates to TRUE. If the Boolean\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg?fit=562%2C155&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg?fit=562%2C155&ssl=1\",\"width\":562,\"height\":155},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"If statement true Python | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"If statement true Python | Example code - EyeHunts","description":"If statement concept works on Boolean true and false. If block codes will execute if the Boolean expression evaluates to TRUE. If the Boolean","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:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/","og_locale":"en_US","og_type":"article","og_title":"If statement true Python | Example code - EyeHunts","og_description":"If statement concept works on Boolean true and false. If block codes will execute if the Boolean expression evaluates to TRUE. If the Boolean","og_url":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-09-08T06:51:07+00:00","article_modified_time":"2022-04-19T12:38:57+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/","name":"If statement true Python | Example code - EyeHunts","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg","datePublished":"2021-09-08T06:51:07+00:00","dateModified":"2022-04-19T12:38:57+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"If statement concept works on Boolean true and false. If block codes will execute if the Boolean expression evaluates to TRUE. If the Boolean","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg?fit=562%2C155&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/09\/If-statement-true-Python.jpg?fit=562%2C155&ssl=1","width":562,"height":155},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/if-statement-true-python-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"If statement true Python | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":16901,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-if-boolean-false\/","url_meta":{"origin":16606,"position":0},"title":"Python if boolean False","author":"Rohit","date":"June 26, 2023","format":false,"excerpt":"In Python, the expression \"if boolean False\" refers to using a boolean value of False as a condition in an if statement. The if statement allows you to execute a block of code only if a certain condition is true. When the boolean value False is used as the condition\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/06\/Python-if-boolean-False.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":16907,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-if-true-statement-example-code\/","url_meta":{"origin":16606,"position":1},"title":"Python if True statement | Example code","author":"Rohit","date":"July 26, 2021","format":false,"excerpt":"Python if True statement works on if the given expression is true. If the statement evaluates the condition as the boolean expression evaluates if it's TRUE, then the block of the statement(s) inside the if statement is executed. The general Python syntax for a simple if statement is: if condition\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python if True statement","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/07\/Python-if-True-statement.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":16905,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-boolean-if-statement-basics\/","url_meta":{"origin":16606,"position":2},"title":"Python boolean if statement | Basics","author":"Rohit","date":"November 9, 2021","format":false,"excerpt":"Python if statement works on the boolean expression true and false statement. If true then the block will execute. Python boolean if example Simple example code Using a Boolean in an If-Statement in Python. Don't forget capital T and F, it is case sensitive. a = True b = False\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python boolean if statement","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Python-boolean-if-.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":16909,"url":"https:\/\/tutorial.eyehunts.com\/python\/boolean-expression-python\/","url_meta":{"origin":16606,"position":3},"title":"Boolean expression Python","author":"Rohit","date":"February 14, 2023","format":false,"excerpt":"Python Boolean expression is an expression that evaluates to produce a result which is a Boolean value. An if statement uses the equal operator == to test if two values are equal and produce (or\u00a0yield) a Boolean value. The Boolean values in Python are True and False, typically used to\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Boolean expression Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2023\/02\/Boolean-expression-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":16593,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-if-not-boolean-example-code\/","url_meta":{"origin":16606,"position":4},"title":"Python if not Boolean | Example code","author":"Rohit","date":"July 21, 2021","format":false,"excerpt":"Using if not Boolean will do a negation of a boolean is the opposite of its current value. A boolean is a primitive data type and its value can be True or False only. Simple If value is False, not value would be True, and the statement(s) in if-block will\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python if not Boolean","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/07\/Python-if-not-Boolean.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":16602,"url":"https:\/\/tutorial.eyehunts.com\/python\/while-boolean-python-example-code\/","url_meta":{"origin":16606,"position":5},"title":"While Boolean Python | Example code","author":"Rohit","date":"July 21, 2021","format":false,"excerpt":"Python While loop uses the Boolean value to executes the loop body while the expression evaluates to (boolean) \"true\". You can use a variable as a condition for your while loop instead of just while True. If you don't set value false then the loop will run for infinite. while\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"While Boolean Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/07\/While-Boolean-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/16606","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=16606"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/16606\/revisions"}],"predecessor-version":[{"id":28520,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/16606\/revisions\/28520"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=16606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=16606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=16606"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=16606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}