python mcq questions
python mcq questions
a) True
b) False
c) None
d) Error
Answer: a) True
a) &&
b) and
c) &
d) ||
Answer: b) and
a) Repeats a condition
b) Reverses the result of a logical expression
c) Skips an expression
d) Converts True to False permanently
a) True
b) False
c) None
d) Error
Answer: a) True
5. In logical programming, which of the following evaluates to True?
a) 0
b) ""
c) []
d) "Python"
Answer: d) "Python"
a) True
b) False
c) None
d) Error
Answer: b) False
a) bool([])
b) bool("hello")
c) bool(42)
d) bool(-1)
Answer: a) bool([])
a) True
b) False
c) None
d) Error
Answer: a) True
9. Which of these expressions is equivalent to not (A or B)?
a) not A and B
b) A and not B
c) not A and not B
d) not A or not B
a) if
b) elif
c) while
d) All of the above
a) 0
b) 3
c) 2
d) None
Answer: b) 3
a) True
b) False
Answer: a) True
13. Which of the following evaluates to True?
a) None
b) {}
c) 1
d) ""
Answer: c) 1
a) x > 5 or x < 10
b) 5 < x < 10
c) x > 10 or x < 5
d) None of these
a) Non-zero integers
b) Non-empty strings
c) Empty lists
d) All of the above
a) True
b) False
c) None
d) Error
Answer: a) True
17. Which operator has the highest precedence in logical programming?
a) and
b) or
c) not
d) All have equal precedence
Answer: c) not
a) True
b) False
c) None
d) Error
Answer: b) False
a) Empty dictionaries
b) Non-empty strings
c) 0
d) None
a) True
b) False
Answer: b) False
21. What is the result of the following code?
x = None
print(not x)
a) True
b) False
c) None
d) Error
Answer: a) True
a) True || False
b) 1 and 0
c) not 2
d) None or True
a) True
b) False
Answer: a) True
a) Booleans only
b) Numbers only
c) Both numbers and booleans
d) None of the above
a) 0
b) 1
c) True
d) None
Answer: b) 1
a) and
b) or
c) not
Answer: b) or
a) True
b) False
c) None
d) Error
Answer: b) False
29. What does the any() function return for the following list?
lst = [0, False, None]
print(any(lst))
a) True
b) False
Answer: b) False
30. What does the all() function return for the following list?
lst = [1, True, "Python"]
print(all(lst))
a) True
b) False
Answer: a) True
a) Prints "Empty"
b) Prints "Not Empty"
c) Error
d) None
32. Which logical operator combines expressions but ensures both are true?
a) or
b) not
c) and
d) None
Answer: c) and
a) True
b) False
Answer: b) False
34. What does the following expression return?
bool(10 and 0)
a) True
b) False
Answer: b) False
35. Which logical operator stops evaluation as soon as it finds the first True
operand?
a) and
b) or
c) not
d) None
Answer: b) or
a) x is True
b) x is False
c) Both are False
d) None of the above
Answer: a) x is True
a) True
b) False
Answer: a) True
Answer: a) True
39. Which of these functions checks if all elements in an iterable are truthy?
a) any()
b) all()
c) bool()
d) None of these
Answer: b) all()
a) True
b) False
Answer: a) True
a) bool({})
b) bool([])
c) bool("")
d) bool("Python")
Answer: d) bool("Python")
a) and
b) or
c) Both
d) None
Answer: c) Both
a) True
b) False
Answer: a) True
a) TRUE
b) True
c) false
d) All of the above
Answer: b) True
a) True
b) False
Answer: b) False
a) True
b) False
Answer: a) True
47. What does the not keyword evaluate to if applied on a non-empty string?
a) True
b) False
Answer: b) False
a) x and y
b) x or y
c) Both
d) None
Answer: c) Both
a) 0
b) 1
c) 2
d) None
Answer: c) 2
a) and
b) or
c) not
d) None
Answer: c) not