{"id":4095,"date":"2022-01-26T15:32:32","date_gmt":"2022-01-26T15:32:32","guid":{"rendered":"https:\/\/ibex.tech\/python\/?p=4095"},"modified":"2025-01-24T08:45:20","modified_gmt":"2025-01-24T08:45:20","slug":"if","status":"publish","type":"post","link":"https:\/\/ibex.tech\/python\/if-comparison-etc\/if","title":{"rendered":"if"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>if my_variable == \"abc\":\n    print(\"Yes\")\n\nif (my_variable_a == \"abc\") and (my_variable_b&gt;= 2.0):\n    print(\"Yes\")\n\n\nif my_variable == 1:\n    print(\"Yes1\")\nelif my_variable  &lt; 2:\n    print(\"Yes2\")\nelif (my_variable  &lt; 3):\n    print(\"Yes3\")\nelse:\n    print(\"No\")<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Multiline if<\/h5>\n\n\n\n<p>Not a problem, you can use whitespace as in C as long as you use surrounding brackets for the whole if statement:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (\n    (my_variable_a == \"abc\") or\n    (my_variable_b == \"xyz\")\n    ):\n    print(\"Yes\")<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Boolean operators<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">NOT Equal<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>if not something_a == 2:\n    print(\"No\")\n\nif not(something_a== 2):\n    print(\"No\")<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Logical AND<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>if (my_variable == 2) and (my_variable == 4):<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Logical OR<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>if (my_variable == 2) or (my_variable == 4):<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Multiline if Not a problem, you can use whitespace as in C as long as you use surrounding brackets for the whole if statement: Boolean operators NOT Equal Logical AND Logical OR<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[324],"tags":[],"class_list":["post-4095","post","type-post","status-publish","format-standard","hentry","category-if-comparison-etc"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/comments?post=4095"}],"version-history":[{"count":13,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4095\/revisions"}],"predecessor-version":[{"id":4848,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/posts\/4095\/revisions\/4848"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/media?parent=4095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/categories?post=4095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/python\/wp-json\/wp\/v2\/tags?post=4095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}