Anyone Can Code.
if (condition):
(code to follow if condition(s) is/are met)
elif:
(alternative code)
else:
(code to execute if none of the conditions are satisfied)
The codes within the if subsection is indented i.e. you will notice when coding yourself that after a conditional statement, the next line will be written slightly ahead instead of directly below the if statement. The indented code is the one which will be followed by the program if the condition is true.
Conditions are dependent on boolean values i.e. True and False.
Your condition can use any operators which return a boolean value. Other conditions will not be
executed by the interpreter. The major operators you can use in conditions are comparison
operators, membership operators, logical operators and identity operators since these
return boolean values. You can also use boolean values themselves to create a condition.
You can find all these operators in our Operators Tutorial.
By using these operators, we can check create pre requisites to a certain lines of code. For example, if we only want our output when two values are equal, then we can use these operators to create a conditional statement.
That's it for this tutorial! Click Next to access the next tutorial!
This site uses cookies to improve your experience as well as for site metrics. To see more, check out our Privacy Policy