Looking For Anything Specific?

Python MCQs


31. What is the output of print(5 != 3)?

a) True

b) False

c) None

d) Error


Answer: a) True



32. Which function returns the number of elements in a list?

a) count()

b) length()

c) len()

d) size()


Answer: c) len()



33. What is the output of print(type(3.5))?

a) <class 'int'>

b) <class 'float'>

c) <class 'double'>

d) Error


Answer: b) <class 'float'>



34. Which keyword is used to exit a loop prematurely?

a) exit

b) continue

c) break

d) stop


Answer: c) break



35. What is the output of print(4 * (2 + 3))?

a) 20

b) 14

c) 10

d) 8


Answer: a) 20



36. How do you create a dictionary in Python?

a) []

b) {} with key-value pairs

c) ()

d) <>


Answer: b) {} with key-value pairs



37. Which method converts a string to lowercase?

a) toLower()

b) lower()

c) tolowercase()

d) convert_lower()


Answer: b) lower()



38. What is the output of print(10 / 2)?

a) 5

b) 5.0

c) 10

d) Error


Answer: b) 5.0



39. Which operator is used for string concatenation?

a) *

b) -

c) +

d) /


Answer: c) +



40. What does list("abc") return?

a) ['abc']

b) ['a', 'b', 'c']

c) ['a', 'bc']

d) Error


Answer: b) ['a', 'b', 'c']



41. How do you create a single-line lambda function?

a) lambda x: x + 2

b) func x: x + 2

c) def lambda(x): x + 2

d) lambda (x): x + 2


Answer: a) lambda x: x + 2



42. What is the output of print(True and False)?

a) True

b) False

c) None

d) Error


Answer: b) False



43. Which method removes a specific element from a list?

a) delete()

b) discard()

c) remove()

d) pop()


Answer: c) remove()



44. What is the output of print('Python'.upper())?

a) PYTHON

b) python

c) Python

d) Error


Answer: a) PYTHON



45. Which of the following is a valid variable name?

a) 1var

b) _var

c) var-name

d) var name


Answer: b) _var





Post a Comment

0 Comments