<div class='tutordiv commonpara'>
<h1>Python If Statement</h1>
<p class="pad10">The <strong>python if statement</strong> is the most commonly used in conditional control statements.
If the condition in the '<strong>if statement</strong>' is true, then the block within the if statement are executed.</p>
<p class="pad10">Python represents the block structure with indentation, not with begin and end brackets. 
There are several benefits to use this indentation. It reduces inconsistency, 
code from different sources follow the same indentation style and eliminates all the curly brackets.</p>
<h2>Syntax of If Statement</h2>
<pre><code><h5>If condition:
<p class="pad10">The condition is a boolean expression that determines whether or not the body will be executed. 
A colon must follow the condition. If the condition is true, the given sequence of statements will be executed.</p>
<p class="pad10">The block is a block of one or more statements to be executed if the condition is true. </p>
<h2>Example of If Statement</h2>
<code>>>> x = 10
>>> if x > 10:
print(x, "is a positive number")
>>> y = 20
>>> if y == 20:
print("y is equal to 20")
y is equal to 20</code></pre>
<img src="/images/python/python-if.jpg"  class="wdth513" alt="Python if statement"/>
<h5>Output of the above code</h5>
<img src="/images/python/python-if-output.jpg"  class="wdth513" alt="Python if statement"/>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- myad -->
<ins class="adsbygoogle"
(adsbygoogle = window.adsbygoogle || []).push({});
<div class="nxtpre">
<div class="previous"><a href="/index.php/python/python-dictionary"><img src="/images/prev.png" alt="previous" class="nxticon"/></a></div>
<div class="next"><a href="/index.php/python/python-if-else"><img src="/images/next.png" alt="next" class="nxticon"/></a></div>