Exercise: Python

Questions for: Conditional Statements

How can you combine multiple conditions using the logical OR operator?
A:
||
B:
or
C:
&&
D:
and
Answer: B
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.
What does the continue statement do in a loop?
A:
Exits the loop
B:
Skips the remaining code in the loop and moves to the next iteration
C:
Repeats the loop indefinitely
D:
Skips the remaining code and exits the loop
Answer: B
The continue statement is used to skip the remaining code in the current iteration of a loop and move on to the next iteration.
Which of the following statements is used for handling exceptions?
A:
try-case
B:
for-in
C:
while-break
D:
try-except
Answer: D
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
What does the in keyword check in Python conditional statements?
A:
Object identity
B:
Membership in a sequence or collection
C:
Inequality
D:
Division
Answer: B
The in keyword is used to test if a value is a member of a sequence or collection, such as a list or a string.
Which comparison operator is used to check for equality?
A:
=
B:
==
C:
===
D:
equals
Answer: B
The double equals (==) operator is used to check if two values are equal in Python.
Ad Slot (Above Pagination)
Quiz