Python Programming - Conditional Statements
Exercise : Conditional Statements - General Questions
- Conditional Statements - General Questions
11.
Which of the following statements is used for handling exceptions?
Answer: Option
Explanation:
The
try-except
statement is used for exception handling in Python. Code within the try
block is executed, and if an exception occurs, it can be caught and handled in the except
block.
try:
# code that might raise an exception
except SomeException:
# code to handle the exception
12.
What does the
continue
statement do in a loop?Answer: Option
Explanation:
The
continue
statement is used to skip the remaining code in the current iteration of a loop and move on to the next iteration.
13.
How can you combine multiple conditions using the logical OR operator?
Answer: Option
Explanation:
The
or
keyword is used as the logical OR operator to combine multiple conditions in an if
statement. At least one of the conditions must be true for the combined condition to be true.
14.
What is the purpose of the
assert
statement?Answer: Option
Explanation:
The
assert
statement is used to test if a given condition is true, and if not, it raises an AssertionError
with an optional error message.
15.
What is the output of the following code?
value = None
if value:
print("Value is None")
else:
print("Value is not None")
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".
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers