Python Programming - Conditional Statements
Exercise : Conditional Statements - General Questions
- Conditional Statements - General Questions
31.
What will be the output of the following code?
num = 0
if num:
print("Non-zero")
else:
print("Zero")
Answer: Option
Explanation:
The condition
if num
checks if num
is truthy. Since num
is 0, which is falsy, the code inside the else
block is executed, printing "Zero."
32.
Which of the following is the correct way to handle multiple exceptions in a
try-except
block?
Answer: Option
Explanation:
The correct syntax is to use a tuple in the
except
clause to handle multiple exceptions.
33.
How can you check if a key exists in a dictionary?
Answer: Option
Explanation:
The
in
keyword is used to check if a key exists in a dictionary in Python.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers