Python Programming - Conditional Statements - Discussion

Discussion Forum : Conditional Statements - General Questions (Q.No. 15)
15.
What is the output of the following code?
value = None
if value:
    print("Value is None")
else:
    print("Value is not None")
Value is None
Value is not None
Error
No output
Answer: Option
Explanation:

In this code, the condition if value: checks whether value evaluates to True. Since value is None, which is considered falsy in Python, the condition evaluates to False.

Therefore, the code block under the else statement gets executed, printing "Value is not None".

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.