Facebook Pixelif-else Statement | Python Tutorial | CodeWithHarry

if-else Statement

An if......else statement works on the following principle:

  • Execute the block of code inside the if statement if the expression evaluates to True. After execution, return to the code outside of the if......else block.
  • Execute the block of code inside the else statement if the expression evaluates to False. After execution, return to the code outside of the if......else block.

If-Else Diagram

Example:

applePrice = 210
budget = 200
if (applePrice <= budget):
    print("Alexa, add 1kg Apples to the cart.")
else:
    print("Alexa, do not add Apples to the cart.")

Output:

Alexa, do not add Apples to the cart.