निम्नलिखित कोड खंड क्या प्रिंट करेगा?
What will following code segment print ?
a = True
b = False
c = False
if a or b and c:
print "HELLO"
else:
print "hello" A
HELLO
B
Hello
C
HellO
D
None of these
Explanation
The correct answer is:
(A) HELLO
Explanation:
- The expression
a or b and cevaluates the logical conditions. - Python evaluates
andbeforeor. So, the expression is evaluated asa or (b and c). - Since
b and cisFalse(because bothbandcareFalse), the condition becomesa or False, which isTrue or False, which results inTrue. - Since the condition is
True, theifblock is executed, and it prints "HELLO".
Output:
(A) HELLO
Correct Answer: A) HELLO