0% found this document useful (0 votes)
2 views

python mcq questions

The document contains a series of multiple-choice questions (MCQs) focused on Python logical programming concepts. Each question tests knowledge on logical operators, expressions, and their outputs in Python. The document provides correct answers for each question, making it a useful resource for learning or reviewing Python logical programming.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

python mcq questions

The document contains a series of multiple-choice questions (MCQs) focused on Python logical programming concepts. Each question tests knowledge on logical operators, expressions, and their outputs in Python. The document provides correct answers for each question, making it a useful resource for learning or reviewing Python logical programming.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Python logical programming MCQs:

1. What is the output of the following code?


print(5 > 3 and 2 < 4)

a) True
b) False
c) None
d) Error

Answer: a) True

2. Which of the following is the logical AND operator in Python?

a) &&
b) and
c) &
d) ||

Answer: b) and

3. What does the not operator do in Python?

a) Repeats a condition
b) Reverses the result of a logical expression
c) Skips an expression
d) Converts True to False permanently

Answer: b) Reverses the result of a logical expression

4. What is the output of the following code?


x = 10
print(x > 5 or x < 3)

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"

6. What is the result of True and False?

a) True
b) False
c) None
d) Error

Answer: b) False

7. Which of the following Python statements evaluates to False?

a) bool([])
b) bool("hello")
c) bool(42)
d) bool(-1)

Answer: a) bool([])

8. What is the output of the following code?


x = True
y = False
print(x or y and not x)

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

Answer: c) not A and not B

10. Which Python keyword is used for logical conditions?

a) if
b) elif
c) while
d) All of the above

Answer: d) All of the above

11. What is the output of the following code?


print(2 and 0 or 3)

a) 0
b) 3
c) 2
d) None

Answer: b) 3

12. What is the value of bool("False")?

a) True
b) False

Answer: a) True
13. Which of the following evaluates to True?

a) None
b) {}
c) 1
d) ""

Answer: c) 1

14. The expression x > 5 and x < 10 is equivalent to:

a) x > 5 or x < 10
b) 5 < x < 10
c) x > 10 or x < 5
d) None of these

Answer: b) 5 < x < 10

15. Which of the following Python objects are "falsy"?

a) Non-zero integers
b) Non-empty strings
c) Empty lists
d) All of the above

Answer: c) Empty lists

16. What is the result of the following code?


print(True or False and True)

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

18. What does the following expression evaluate to?


not (True or False)

a) True
b) False
c) None
d) Error

Answer: b) False

19. Which Python data type is inherently "truthy"?

a) Empty dictionaries
b) Non-empty strings
c) 0
d) None

Answer: b) Non-empty strings

20. What is the output of this code?


print(bool([] or 0))

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

22. Which of these is a valid Python logical expression?

a) True || False
b) 1 and 0
c) not 2
d) None or True

Answer: d) None or True

23. What is the output of the following code?


print(bool('False'))

a) True
b) False

Answer: a) True

24. Logical operators in Python work on:

a) Booleans only
b) Numbers only
c) Both numbers and booleans
d) None of the above

Answer: c) Both numbers and booleans

25. Which of the following evaluates to False?


a) not 0
b) not None
c) not True
d) not []

Answer: c) not True

26. What is the result of 1 or 0 in Python?

a) 0
b) 1
c) True
d) None

Answer: b) 1

27. Which logical operator has the lowest precedence?

a) and
b) or
c) not

Answer: b) or

28. What is the result of this expression?


not (True and False or True)

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

31. What is the result of this code?


x = []
if not x:
print("Empty")

a) Prints "Empty"
b) Prints "Not Empty"
c) Error
d) None

Answer: a) Prints "Empty"

32. Which logical operator combines expressions but ensures both are true?

a) or
b) not
c) and
d) None

Answer: c) and

33. What is the result of the following code?


x = "Python"
print(bool(x 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

36. The expression x and y returns y when:

a) x is True
b) x is False
c) Both are False
d) None of the above

Answer: a) x is True

37. What is the result of this code?


x = 0
y = 10
print(bool(x or y))

a) True
b) False

Answer: a) True

38. What is the result of True and not False?


a) True
b) False
c) None
d) Error

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()

40. What is the result of this code?


x = [1, 2, 3]
print(bool(x))

a) True
b) False

Answer: a) True

41. Which of these statements evaluates to True?

a) bool({})
b) bool([])
c) bool("")
d) bool("Python")

Answer: d) bool("Python")

42. Which logical operator ensures short-circuit evaluation?

a) and
b) or
c) Both
d) None
Answer: c) Both

43. What does the following code output?


print(True or False and False)

a) True
b) False

Answer: a) True

44. Which of the following is a valid Boolean value in Python?

a) TRUE
b) True
c) false
d) All of the above

Answer: b) True

45. What is the value of this expression?


not (1 and 0 or 1)

a) True
b) False

Answer: b) False

46. What is the output of this code?


x = 5
y = 10
print(x < y and y > 5)

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

48. Which of these is a valid short-circuit expression?

a) x and y
b) x or y
c) Both
d) None

Answer: c) Both

49. What is the result of this code?


print(0 or 1 and 2)

a) 0
b) 1
c) 2
d) None

Answer: c) 2

50. Which logical operator inverts a Boolean value?

a) and
b) or
c) not
d) None

Answer: c) not

You might also like