Computer Applications
What is the output of following code ?
if None :
print "Up"
else:
print "Down"
- Up
- Down
- No output
- Up Down
Python Control Flow
2 Likes
Answer
Down
Reason — Since None
is treated as false, the if condition results in false. The block of if will be ignored and the else block will be executed and Down
will be printed on the output screen.
Answered By
2 Likes
Related Questions
Which of the following is/are not a valid Python loop ?
- for
- while
- iter
- repeat
What will be the output of following code ?
for i in range(1) : print i
- 0
- 1
- No output
- Error in code
Which of the following is used to define a block of code (e.g., body of if or body of a loop) in Python ?
- { }
- ( )
- indentation
- Quotation
What will the output of following code ?
for i in range(1, 0) : print i
- 0
- 1
- No output
- Error in code