What does the following code print: print(10 != 5)?
a) True
b) False
c) 10
d) 5
Answer:
a) True
Explanation:
The expression 10 != 5
uses the inequality operator !=
, which checks whether two values are not equal. In this case, since 10 is not equal to 5, the expression evaluates to True
.
result = 10 != 5 # result is True
Understanding comparison operators like !=
is fundamental in writing conditional statements and making decisions in your code. These operators allow you to compare values and control the flow of your programs based on these comparisons.
Using !=
is particularly useful in loops, conditionals, and assertions, where you need to ensure that two values are different before proceeding with a block of code.