निम्नलिखित कोड खंड क्या प्रिंट करेगा?
What will following code segment print ?
a = True
b = False
c = False
if a or b and c:
print "HELLO"
else:
print "hello"
A)
B)
C)
D)
Explanation:
The correct answer is:
(A) HELLO
Explanation:
- The expression
a or b and c
evaluates the logical conditions. - Python evaluates
and
beforeor
. So, the expression is evaluated asa or (b and c)
. - Since
b and c
isFalse
(because bothb
andc
areFalse
), the condition becomesa or False
, which isTrue or False
, which results inTrue
. - Since the condition is
True
, theif
block is executed, and it prints "HELLO".
Output:
(A) HELLO