Python Programming - Conditional Statements
Exercise : Conditional Statements - General Questions
- Conditional Statements - General Questions
6.
Which logical operator is used to combine multiple conditions in an
if
statement?
Answer: Option
Explanation:
The
and
keyword is used as the logical AND operator to combine multiple conditions in an if
statement. Both conditions must be true for the combined condition to be true.
7.
What will be the output of the following code?
num = 0
if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else:
print("Zero")
Answer: Option
Explanation:
The code checks if
num
is greater than 0, less than 0, or equal to 0. Since num
is 0, the code inside the else
block will be executed, printing "Zero."
8.
In Python, how can you represent the logical NOT operator in an
if
statement?Answer: Option
Explanation:
The not
keyword is used as the logical NOT operator in Python. It is used to negate the truth value of a condition.
The !=
operator in Python is used for inequality comparison, not for logical negation. It checks if two values are not equal to each other. It's not used directly to represent logical NOT in an if statement.
9.
Which comparison operator is used to check for equality?
Answer: Option
Explanation:
The double equals (
==
) operator is used to check if two values are equal in Python.
10.
What does the
in
keyword check in Python conditional statements?
Answer: Option
Explanation:
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.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers