100 Python MCQ (Multiple Choice Questions) with Answers

1) What is the correct extension of a Python file?
  1. .python
  2. .p
  3. .py
  4. .pyt
Show Answer
Answer: c


2) Who created the Python programming language?

  1. Guido van Rossum
  2. James Gosling
  3. Dennis Ritchie
  4. Bjarne Stroustrup
Show Answer
Answer: a


3) Which of the following is the correct syntax to output “Hello World” in Python?

  1. echo(“Hello World”)
  2. print(“Hello World”)
  3. p(“Hello World”)
  4. System.out.println(“Hello World”)
Show Answer
Answer: b


4) How do you insert comments in Python code?

  1. // This is a comment
  2. /* This is a comment */
  3. # This is a comment
  4. <!– This is a comment –>
Show Answer
Answer: c


5) Which data type is immutable in Python?

  1. List
  2. Dictionary
  3. Set
  4. Tuple
Show Answer
Answer: d


6) What is the result of 3 ** 2 in Python?

  1. 6
  2. 9
  3. 8
  4. 5
Show Answer
Answer: b


7) Which keyword is used to define a function in Python?

  1. func
  2. define
  3. def
  4. function
Show Answer
Answer: c


8) Which of the following operators performs integer division in Python?

  1. /
  2. //
  3. %
  4. \
Show Answer
Answer: b


9) What is the output of len([10, 20, 30])?

  1. 2
  2. 3
  3. 4
  4. Error
Show Answer
Answer: b


10) How do you create a variable with the numeric value 5?

  1. x = 5
  2. int x = 5
  3. x = int(5)
  4. Both a and c
Show Answer
Answer: d


11) Which collection is ordered, changeable, and allows duplicate members?

  1. Tuple
  2. Dictionary
  3. Set
  4. List
Show Answer
Answer: d


12) Which collection is unordered, unchangeable, and unindexed?

  1. Set
  2. List
  3. Tuple
  4. Dictionary
Show Answer
Answer: a


13) What function is used to convert a value into an integer?

  1. integer()
  2. parse()
  3. int()
  4. str()
Show Answer
Answer: c


14) What will type(3.14) return?

  1. <class ‘int’>
  2. <class ‘float’>
  3. <class ‘double’>
  4. <class ‘decimal’>
Show Answer
Answer: b


15) How do you start a for loop in Python?

  1. for x in y:
  2. for x = 1 to 10
  3. for (i = 0; i < 10; i++)
  4. foreach x in y
Show Answer
Answer: a


16) Which method is used to remove whitespace from both the beginning and end of a string?

  1. pstrip()
  2. trim()
  3. strip()
  4. len()
Show Answer
Answer: c


17) What keyword is used to raise an exception in Python?

  1. throw
  2. raise
  3. try
  4. catch
Show Answer
Answer: b


18) What is the correct syntax for an if statement in Python?

  1. if x == 5 then:
  2. if (x == 5)
  3. if x == 5:
  4. if x = 5:
Show Answer
Answer: c


19) Which operator is used to check if two values are equal?

  1. =
  2. ==
  3. ===
  4. is
Show Answer
Answer: b


20) What is the output of bool(“”)?

  1. True
  2. False
  3. None
  4. Error
Show Answer
Answer: b


21) Which method adds an item to the end of a list?

  1. add()
  2. append()
  3. insert()
  4. push()
Show Answer
Answer: b


22) How do you access the value associated with the key “age” in dictionary d?

  1. d.age
  2. d[“age”]
  3. d(age)
  4. d[age]
Show Answer
Answer: b


23) What statement is used to exit a loop prematurely?

  1. exit
  2. return
  3. break
  4. stop
Show Answer
Answer: c


24) Which built-in function returns a range of numbers?

  1. sequence()
  2. range()
  3. loop()
  4. list()
Show Answer
Answer: b


25) What is the logical operator for logical AND in Python?

  1. &&
  2. and
  3. &
  4. AND
Show Answer
Answer: b


26) Which symbol is used to pass variable-length positional arguments to a function?

  1. *
  2. **
  3. &
  4. #
Show Answer
Answer: a


27) Which keyword is used to create a class in Python?

  1. struct
  2. object
  3. class
  4. define
Show Answer
Answer: c


28) What will 2 + 3 * 4 evaluate to?

  1. 20
  2. 14
  3. 24
  4. 18
Show Answer
Answer: b


29) What is the output of “python”[1:4]?

  1. pyt
  2. yth
  3. ytho
  4. pyth
Show Answer
Answer: b


30) How do you create an empty dictionary in Python?

  1. {}
  2. []
  3. ()
  4. set()
Show Answer
Answer: a


31) What keyword handles exceptions in Python?

  1. catch
  2. except
  3. handle
  4. error
Show Answer
Answer: b


32) Which built-in function returns the highest value in a list?

  1. top()
  2. max()
  3. highest()
  4. upper()
Show Answer
Answer: b


33) What is the output of type([])?

  1. <class ‘set’>
  2. <class ‘tuple’>
  3. <class ‘array’>
  4. <class ‘list’>
Show Answer
Answer: d


34) What keyword is used to import a module in Python?

  1. import
  2. include
  3. require
  4. using
Show Answer
Answer: a


35) What is the default return value of a function that doesn’t explicitly return anything?

  1. 0
  2. False
  3. None
  4. Null
Show Answer
Answer: c


36) Which method converts a string to all uppercase letters?

  1. uppercase()
  2. upper()
  3. toUpper()
  4. cap()
Show Answer
Answer: b


37) How do you remove an item at a specific index from a list?

  1. remove()
  2. delete()
  3. pop()
  4. discard()
Show Answer
Answer: c


38) What does PIP stand for in Python?

  1. Preferred Installer Program
  2. Python Installer Package
  3. Program Instruction Process
  4. Python Integration Program
Show Answer
Answer: a


39) Which operator is used for exponentiation?

  1. ^
  2. **
  3. pow
  4. exp
Show Answer
Answer: b


40) What is the output of bool(0)?

  1. True
  2. False
  3. None
  4. Error
Show Answer
Answer: b


41) Which statement skips the current iteration of a loop and continues with the next?

  1. pass
  2. skip
  3. continue
  4. next
Show Answer
Answer: c


42) What function returns the absolute value of a number?

  1. absolute()
  2. abs()
  3. fabs()
  4. val()
Show Answer
Answer: b


43) Which special variable represents the class instance in class methods?

  1. this
  2. self
  3. instance
  4. me
Show Answer
Answer: b


44) What is the output of “hello”.find(“l”)?

  1. 2
  2. 3
  3. 1
  4. 0
Show Answer
Answer: a


45) Which data structure stores keys and values?

  1. List
  2. Tuple
  3. Dictionary
  4. Set
Show Answer
Answer: c


46) How do you create an anonymous or inline function in Python?

  1. def
  2. lambda
  3. func
  4. inline
Show Answer
Answer: b


47) What method removes all items from a dictionary?

  1. deleteAll()
  2. remove()
  3. clear()
  4. purge()
Show Answer
Answer: c


48) What is the output of 10 % 3?

  1. 3
  2. 1
  3. 0
  4. 3.33
Show Answer
Answer: b


49) Which method converts a list of strings into a single string separated by a delimiter?

  1. concat()
  2. join()
  3. merge()
  4. split()
Show Answer
Answer: b


50) What is the result of str(123)?

  1. 123
  2. ‘123’
  3. Error
  4. [123]
Show Answer
Answer: b


51) How do you open a file named “test.txt” for reading in Python?

  1. open(“test.txt”, “r”)
  2. open(“test.txt”, “w”)
  3. open(“test.txt”, “read”)
  4. file(“test.txt”)
Show Answer
Answer: a


52) What method splits a string into a list of substrings?

  1. slice()
  2. split()
  3. break()
  4. separate()
Show Answer
Answer: b


53) Which keyword is used to test if a sequence contains a specific item?

  1. in
  2. contains
  3. exists
  4. has
Show Answer
Answer: a


54) What is the output of list(range(3))?

  1. [1, 2, 3]
  2. [0, 1, 2, 3]
  3. [0, 1, 2]
  4. [1, 2]
Show Answer
Answer: c


55) Which error occurs when a variable is used before it is defined?

  1. ValueError
  2. TypeError
  3. NameError
  4. KeyError
Show Answer
Answer: c


56) What does “is” operator evaluate?

  1. Values equality
  2. Identity (same object in memory)
  3. Data types equality
  4. Length equality
Show Answer
Answer: b


57) What is the output of “a” + “b”?

  1. ab
  2. a b
  3. Error
  4. [“a”, “b”]
Show Answer
Answer: a


58) How do you get the last item of a list lst?

  1. lst[last]
  2. lst[-1]
  3. lst[0]
  4. lst.last()
Show Answer
Answer: b


59) Which block is always executed whether an exception occurs or not?

  1. try
  2. except
  3. else
  4. finally
Show Answer
Answer: d


60) What keyword creates a generator function?

  1. return
  2. yield
  3. generate
  4. produce
Show Answer
Answer: b


61) What is the output of min([5, 2, 8, 1])?

  1. 5
  2. 2
  3. 8
  4. 1
Show Answer
Answer: d


62) Which method adds all elements of an iterable to a list?

  1. append()
  2. extend()
  3. add()
  4. push()
Show Answer
Answer: b


63) What will set([1, 2, 2, 3]) yield?

  1. {1, 2, 2, 3}
  2. {1, 2, 3}
  3. [1, 2, 3]
  4. (1, 2, 3)
Show Answer
Answer: b


64) Which module in Python provides tools for working with regular expressions?

  1. regex
  2. re
  3. pyre
  4. string
Show Answer
Answer: b


65) What is the correct syntax for a list comprehension that doubles each element in nums?

  1. [x * 2 for x in nums]
  2. for x in nums double(x)
  3. [double(x) : x in nums]
  4. [x for x * 2 in nums]
Show Answer
Answer: a


66) What function returns the length of an object?

  1. count()
  2. size()
  3. len()
  4. length()
Show Answer
Answer: c


67) What is the output of bool(None)?

  1. True
  2. False
  3. None
  4. Error
Show Answer
Answer: b


68) How do you convert a string to lowercase?

  1. lower()
  2. toLower()
  3. downcase()
  4. small()
Show Answer
Answer: a


69) Which method reverses a list in place?

  1. reverse()
  2. reversed()
  3. flip()
  4. invert()
Show Answer
Answer: a


70) What is the result of “Python”[::-1]?

  1. Python
  2. nohtyP
  3. P
  4. n
Show Answer
Answer: b


71) Which operator is used for bitwise AND?

  1. and
  2. &
  3. &&
  4. |
Show Answer
Answer: b


72) What built-in module gives access to math functions like sqrt and sin?

  1. math
  2. sys
  3. cmath
  4. numbers
Show Answer
Answer: a


73) What is the primary constructor method for a Python class?

  1. __create__()
  2. __init__()
  3. __construct__()
  4. __main__()
Show Answer
Answer: b


74) What is the result of float(5)?

  1. 5
  2. 5.0
  3. “5.0”
  4. Error
Show Answer
Answer: b


75) What does the pass statement do?

  1. Terminate program execution
  2. Skip to the next iteration
  3. Do nothing (null statement)
  4. Return a value
Show Answer
Answer: c


76) How do you pass keyword-based variable arguments to a function?

  1. *args
  2. **kwargs
  3. &kwargs
  4. #args
Show Answer
Answer: b


77) What exception is raised when dividing by zero?

  1. ArithmeticError
  2. ZeroDivisionError
  3. NullPointerError
  4. MathError
Show Answer
Answer: b


78) Which built-in function pairs elements from two or more iterables?

  1. pair()
  2. zip()
  3. combine()
  4. map()
Show Answer
Answer: b


79) What will all([True, True, False]) evaluate to?

  1. True
  2. False
  3. None
  4. Error
Show Answer
Answer: b


80) What will any([False, True, False]) evaluate to?

  1. True
  2. False
  3. None
  4. Error
Show Answer
Answer: a


81) What is the output of 3 == 3.0?

  1. True
  2. False
  3. Error
  4. None
Show Answer
Answer: a


82) How do you delete a variable in Python?

  1. delete x
  2. del x
  3. remove(x)
  4. drop x
Show Answer
Answer: b


83) Which statement opens a file and automatically closes it when finished?

  1. open file as f:
  2. using open(“file”) as f:
  3. with open(“file”) as f:
  4. file f = open(“file”)
Show Answer
Answer: c


84) What is the output of “Hello, World!”.startswith(“Hello”)?

  1. True
  2. False
  3. None
  4. Error
Show Answer
Answer: a


85) What does isinstance(5, int) return?

  1. False
  2. True
  3. int
  4. Error
Show Answer
Answer: b


86) What is the value of x after x = 10; x += 5?

  1. 10
  2. 5
  3. 15
  4. 50
Show Answer
Answer: c


87) How do you copy a list lst without modifying the original?

  1. lst.copy()
  2. lst[:]
  3. list(lst)
  4. All of the above
Show Answer
Answer: d


88) What method inserts an element at a specific index in a list?

  1. append()
  2. add()
  3. insert()
  4. push()
Show Answer
Answer: c


89) What module provides access to command-line arguments?

  1. os
  2. sys
  3. process
  4. env
Show Answer
Answer: b


90) What is the output of “Py” * 3?

  1. Py3
  2. PyPyPy
  3. Error
  4. Py Py Py
Show Answer
Answer: b


91) Which error occurs when a key is not found in a dictionary?

  1. IndexError
  2. ValueError
  3. KeyError
  4. LookupError
Show Answer
Answer: c


92) What function takes a function and an iterable and applies the function to all items?

  1. filter()
  2. map()
  3. reduce()
  4. apply()
Show Answer
Answer: b


93) What function filters elements from an iterable based on a condition function?

  1. filter()
  2. select()
  3. map()
  4. extract()
Show Answer
Answer: a


94) What is the output of round(3.57, 1)?

  1. 3.5
  2. 3.6
  3. 4.0
  4. 3
Show Answer
Answer: b


95) Which method returns a dictionary’s keys as a view object?

  1. dict.get_keys()
  2. dict.keys()
  3. dict.values()
  4. dict.items()
Show Answer
Answer: b


96) What is the output of bool([0])?

  1. False
  2. True
  3. None
  4. Error
Show Answer
Answer: b


97) How do you import only the pi constant from the math module?

  1. import pi from math
  2. from math import pi
  3. import math.pi
  4. using math.pi
Show Answer
Answer: b


98) What built-in method converts a list to a tuple?

  1. tuple()
  2. toTuple()
  3. cast_tuple()
  4. set()
Show Answer
Answer: a


99) What does the enumerate() function return?

  1. Only the elements of an iterable
  2. Only indices of an iterable
  3. Index-element pairs as tuples
  4. Sorted list of elements
Show Answer
Answer: c


100) What is the output of sum([1, 2, 3, 4])?

  1. 10
  2. 24
  3. 4
  4. Error
Show Answer
Answer: a

 

MCQ Tutorial
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment