Python interview MCQs

 

  1. Which symbol is used for comments in Python?
    A. //
    B. #
    C. <!-- -->
    D. /* */
    Answer: B

  2. Which data type is immutable?
    A. List
    B. Dictionary
    C. Tuple
    D. Set
    Answer: C

  3. What is the output of type(10)?
    A. <class 'str'>
    B. <class 'int'>
    C. <class 'float'>
    D. <class 'list'>
    Answer: B

  4. Which function returns the length of an object?
    A. size()
    B. count()
    C. len()
    D. length()
    Answer: C

  5. Which loop is used when the number of iterations is unknown?
    A. for
    B. while
    C. do-while
    D. loop
    Answer: B

  6. Which operator performs exponentiation?
    A. ^
    B. **
    C. *
    D. //
    Answer: B

  7. What is the output of 3 * 'Hi'?
    A. Hi
    B. 3Hi
    C. HiHiHi
    D. Error
    Answer: C

  8. Which module is used for regular expressions?
    A. regex
    B. reg
    C. re
    D. expr
    Answer: C

  9. Which statement is used to handle exceptions?
    A. try
    B. throw
    C. error
    D. catch
    Answer: A

  10. What is None in Python?
    A. Zero
    B. Boolean false
    C. Absence of value
    D. Empty list
    Answer: C

  11. Which is not a valid Python data type?
    A. tuple
    B. array
    C. set
    D. list
    Answer: B

  12. Which of these defines a function?
    A. function test():
    B. def test():
    C. fun test():
    D. create test():
    Answer: B

  13. Which operator is used for floor division?
    A. /
    B. //
    C. %
    D. **
    Answer: B

  14. What does break do?
    A. Terminates loop
    B. Skips iteration
    C. Restarts loop
    D. Exits program
    Answer: A

  15. Which method adds an element to a list?
    A. add()
    B. insert()
    C. append()
    D. push()
    Answer: C

  16. What does pop() do in a list?
    A. Removes last element
    B. Removes first element
    C. Removes all elements
    D. Adds element
    Answer: A

  17. Which converts a string to an integer?
    A. str()
    B. float()
    C. int()
    D. chr()
    Answer: C

  18. Which of the following is unordered?
    A. List
    B. Tuple
    C. Set
    D. String
    Answer: C

  19. Python was developed by:
    A. Dennis Ritchie
    B. Guido van Rossum
    C. James Gosling
    D. Bjarne Stroustrup
    Answer: B

  20. Which is used to install packages?
    A. installpy
    B. pkg
    C. pip
    D. pyinstall
    Answer: C

  21. Which keyword creates a class?
    A. class
    B. define
    C. struct
    D. object
    Answer: A

  22. Self in a class refers to:
    A. Parent class
    B. Current object
    C. Module
    D. Variable
    Answer: B

  23. Which method is a constructor?
    A. start()
    B. init()
    C. begin()
    D. constructor()
    Answer: B

  24. Which keyword is used to inherit a class?
    A. using
    B. inherit
    C. extends
    D. class Child(Parent)
    Answer: D

  25. Which of the following is used for documentation?
    A. Single quotes
    B. Multi-line comment
    C. Docstring (""" """)
    D. # comment
    Answer: C

  26. Which function is used to get input from user?
    A. scanf()
    B. read()
    C. input()
    D. enter()
    Answer: C

  27. What does strip() do?
    A. Removes spaces
    B. Removes first character
    C. Adds spaces
    D. Removes integers
    Answer: A

  28. Which is faster?
    A. List
    B. Tuple
    C. Set
    D. Dictionary
    Answer: B

  29. Which library is used for data manipulation?
    A. numpy
    B. pandas
    C. math
    D. random
    Answer: B

  30. Which symbol is used for logical AND?
    A. &
    B. &&
    C. and
    D. +
    Answer: C

  31. Which of the following is True?
    A. Python is case-insensitive
    B. SUM and sum are same
    C. Python is case-sensitive
    D. Variables can start with number
    Answer: C

  32. Which method returns keys of a dictionary?
    A. dict.keys()
    B. dict.get()
    C. dict.items()
    D. dict.values()
    Answer: A

  33. Which converts a list to a tuple?
    A. set()
    B. list()
    C. tuple()
    D. dict()
    Answer: C

  34. What is pass used for?
    A. Exits loop
    B. Does nothing
    C. Deletes variable
    D. Prints message
    Answer: B

  35. Which operator checks identity?
    A. ==
    B. is
    C. equals
    D. :=
    Answer: B

  36. Which function gives the max value?
    A. high()
    B. max()
    C. maximum()
    D. top()
    Answer: B

  37. Which function returns absolute value?
    A. abs()
    B. absolute()
    C. fabs()
    D. val()
    Answer: A

  38. Python supports which programming style?
    A. Procedural
    B. Object-Oriented
    C. Functional
    D. All of the above
    Answer: D

  39. Which keyword defines an anonymous function?
    A. def
    B. lambda
    C. fun
    D. anon
    Answer: B

  40. What does continue do?
    A. Ends loop
    B. Skips current iteration
    C. Stops program
    D. Restarts system
    Answer: B

  41. Which is not a keyword?
    A. yield
    B. async
    C. global
    D. print
    Answer: D

  42. What does open() return?
    A. List
    B. String
    C. File object
    D. None
    Answer: C

  43. Which method closes a file?
    A. stop()
    B. close()
    C. exit()
    D. end()
    Answer: B

  44. Which keyword is used with exceptions?
    A. throw
    B. expect
    C. except
    D. error
    Answer: C

  45. What does isinstance() check?
    A. Value equality
    B. Type compatibility
    C. Memory location
    D. Loop iteration
    Answer: B

  46. Which library supports arrays and mathematical operations?
    A. pandas
    B. numpy
    C. random
    D. math
    Answer: B

  47. Which retrieves current working directory?
    A. os.getcwd()
    B. os.getdir()
    C. os.path()
    D. os.dir()
    Answer: A

  48. Which data type stores key-value pairs?
    A. List
    B. Tuple
    C. Dictionary
    D. Set
    Answer: C

  49. Which function converts a value into a string?
    A. chr()
    B. str()
    C. ord()
    D. int()
    Answer: B

  50. What is Python's file extension?
    A. .pn
    B. .pt
    C. .py
    D. .pyc only

    Answer: C

No comments:

Post a Comment