if

if

The following example will print a message, if x has a value greater than 100:
x = 101
if x > 100:
   print("x is big")


After the if keyword, there is a condition. This condition often, but not always, compares two values and gives an answer that is either True or False. If it is True, then the subsequent indented lines will all be executed. It is quite common to want to do one thing if a condition is True and something different if the answer is False. In this case, the else command is used with if, as shown in this
example:


x = 101
if x > 100:
   print("x is big")
else:
   print("x is small")

===========================

No comments:

Post a Comment