Checking for Inequality:
- To determine whether two values are not equal, you can combine an exclamation point and an equal sign ( != ).
- ! Represents not
- Example: Inequality operator with an if statement
python
1requestedTopping = "pepperoni"
2
3if requestedTopping != "anchovies":
4 print("Hold the anchovies!")- In line 3 we compare the value of requestedTopping (i.e., pepperoni) to the value โanchoviesโ.
- If these two values do not match, Python returns True and executes the code following the if statement. If the two values match, Python returns False and does not run the code following the if statement.
- Output:
1Hold the anchovies!