The if - else statement checks the condition and executes the if block of code when the condition is True, and if the condition is False, it will execute the else block of code.
Syntax of the if - else statement
if condition:
statement 1
else:
statement 2
If the condition is True, then statement 1 will be executed if the condition is False, statement 2 will be executed. See the following flowchart for more detail.
Example:
password = input("Enter Password")
if password == "123456789"
print("Password is correct!")
else:
print("Password is not correct!")
Output 1:
Input: 123456789
Output: Password is correct!
Output 2:
Input: 123
Output: Password is not correct!