Python Programming - Operators

Exercise : Operators - General Questions
  • Operators - General Questions
11.
What is the output of the following code?
x = 10
y = 5
result = x != y and x > y

print(result)
True
False
None
Error
Answer: Option
Explanation:

The != operator is used to check if two values are not equal. In the code, x != y means 10 is not equal to 5, which is True.

The and operator returns True only if both expressions are True.

So, the expression x != y and x > y becomes True and True, which evaluates to True.


12.
What is the output of the following code?
a = 5
b = 3
c = 7
print(a + b * c)
26
56
22
36
Answer: Option
Explanation:
The multiplication operator has higher precedence than the addition operator, so b * c is evaluated first and then added to a.
a + b * c
= 5 + 3 * 7
= 5 + 21
= 26

13.
What is the result of the following code?
a = 8
b = 3
print(a / b)
2.6666666666666665
2.6666666666666667
2.67
2.6
Answer: Option
Explanation:
The division operator returns a float value in Python 3.x. In this case, a / b is equal to 2.6666666666666665.

14.
What is the result of the expression: True and False ?
True
False
None
Error
Answer: Option
Explanation:

The and operator in Python is a logical operator that returns True if both operands are true, and False otherwise.

In this case, True and False are the operands, and since the second operand is false, the result is False.


15.
What is the result of the expression 5 == "5"?
True
False
None
Error
Answer: Option
Explanation:
The == operator in Python is used to compare the equality of two operands. In this case, the operands are 5 and "5". Although they look similar, they are not equal because one is an integer and the other is a string. Therefore, the result of 5 == "5" is False.