What are the Control Statements in Python?
It is common for programs to execute statements based on some conditions.
You can learn about python if .. else ... statement in this section.
First of all you should be aware of Relational operators.These are as follows:
<= < > >= == != | smaller than or equal to smaller than greater than greater than or equal to equal to not equal to |
Comparision will always result as a boolean value i.e True or False . True and False are python keywords.
>>> 1 >4
False >>> 3 == 3 True >>> 12 >10 True |
Now we'll learn the syntax of If statement :
if boolean-expression:
#statements else: #statements |
Applying If statement to print even or odd:
i = 4
if i % 2 == 0: print("Even") else: print("Odd") |
else is optional you can only use if clause if you want.
If...Else
Ayesha
Tech writer at newsandstory
Total 660 views