MCQ Related “Python”

  1. Which of the following is the correct file extension for Python files?
    • a) .python
    • b) .py
    • c) .pt
    • d) .p
  2. What is the correct syntax to output “Hello, World” in Python?
    • a) print(“Hello, World”)
    • b) echo “Hello, World”
    • c) console.log(“Hello, World”)
    • d) printf(“Hello, World”)
  3. How do you insert a comment in Python?
    • a) // This is a comment
    • b) /* This is a comment */
    • c) # This is a comment
    • d) <!– This is a comment –>
  4. Which of the following data types is not supported in Python?
    • a) Lists
    • b) Tuples
    • c) Arrays
    • d) Sets
  5. What is the keyword used to define a function in Python?
    • a) func
    • b) define
    • c) def
    • d) function
  6. What will be the output of the following code: print(type(5))?
    • a) int
    • b) str
    • c) float
    • d) class
  7. Which of the following is the correct way to create a list in Python?
    • a) list = (1, 2, 3)
    • b) list = [1, 2, 3]
    • c) list = {1, 2, 3}
    • d) list = <1, 2, 3>
  8. How can you create a dictionary in Python?
    • a) dict = [1: “one”, 2: “two”]
    • b) dict = {1: “one”, 2: “two”}
    • c) dict = (1: “one”, 2: “two”)
    • d) dict = <1: “one”, 2: “two”>
  9. What keyword is used to create a conditional statement in Python?
    • a) if
    • b) when
    • c) else
    • d) switch
  10. Which operator is used for exponentiation in Python?
    • a) ^
    • b) **
    • c) //
    • d) exp
  11. What will be the result of 3 * 2 ** 2?
    • a) 12
    • b) 9
    • c) 6
    • d) 8
  12. How do you start a while loop in Python?
    • a) while (x < y) {
    • b) while x < y:
    • c) while x < y
    • d) while (x < y):
  13. Which of the following is used to handle exceptions in Python?
    • a) try
    • b) catch
    • c) handle
    • d) except
  14. What is the output of len("Python")?
    • a) 6
    • b) 7
    • c) 5
    • d) 0
  15. Which of the following keyword is used to exit a loop in Python?
    • a) exit
    • b) break
    • c) stop
    • d) continue
  16. How do you create a class in Python?
    • a) class MyClass:
    • b) MyClass class:
    • c) class: MyClass
    • d) MyClass = class()
  17. What is the correct way to call a function named my_function?
    • a) my_function[]
    • b) my_function{}
    • c) my_function()
    • d) my_function;
  18. Which function is used to read a file in Python?
    • a) readfile()
    • b) open()
    • c) read()
    • d) get()
  19. What will be the output of print("hello" + "world")?
    • a) helloworld
    • b) hello world
    • c) hello+world
    • d) hello world!
  20. How do you find the maximum value in a list?
    • a) max(list)
    • b) list.max()
    • c) maximum(list)
    • d) list.maximum()
  21. Which of the following statements about Python’s pass statement is true?
    • a) It is used to exit a loop.
    • b) It does nothing and is a placeholder.
    • c) It breaks a function.
    • d) It continues to the next iteration of a loop.
  22. How do you define a private variable in Python?
    • a) _variable
    • b) #variable
    • c) $variable
    • d) variable
  23. What is the length of the list [1, 2, 3, 4, 5]?
    • a) 5
    • b) 4
    • c) 6
    • d) 0
  24. Which keyword is used to import a module in Python?
    • a) include
    • b) import
    • c) require
    • d) use
  25. What will be the output of print(0.1 + 0.2 == 0.3)?
    • a) True
    • b) False
    • c) None
    • d) Error
  26. What is an immutable data type in Python?
    • a) List
    • b) Set
    • c) Dictionary
    • d) Tuple
  27. Which of the following is a built-in data type in Python?
    • a) char
    • b) bool
    • c) string
    • d) all of the above
  28. How do you write a single-line comment in Python?
    • a) // Comment
    • b) # Comment
    • c) — Comment
    • d) /* Comment */
  29. Which module is used for regular expressions in Python?
    • a) regex
    • b) re
    • c) regexes
    • d) regular
  30. What keyword is used to define a constant in Python?
    • a) const
    • b) final
    • c) constant
    • d) None (Python does not have a constant keyword)
  31. How do you delete an element from a list in Python?
    • a) remove(element)
    • b) del list[element]
    • c) list.remove(element)
    • d) all of the above
  32. Which of the following denotes a dictionary in Python?
    • a) []
    • b) ()
    • c) {}
    • d) <>
  33. How can you check if a key exists in a dictionary?
    • a) key in dictionary
    • b) dictionary.has_key(key)
    • c) key in dictionary.keys()
    • d) all of the above
  34. What does the break statement do in a loop?
    • a) Skips the rest of the current iteration
    • b) Exits the loop
    • c) Continues with the next iteration
    • d) Terminates the program
  35. What is the output of print("Python"[0])?
    • a) P
    • b) p
    • c) Python
    • d) Error
  36. Which of the following will NOT raise an error?
    • a) True + 1
    • b) “1” + 1
    • c) 1 + 1
    • d) “Hello” + 5
  37. Which Python statement is used for iteration?
    • a) loop
    • b) for
    • c) iterate
    • d) iterate for
  38. To create a new file in Python, what mode do you use?
    • a) “r”
    • b) “w”
    • c) “a”
    • d) “r+”
  39. How do you convert a string into a list in Python?
    • a) str.split()
    • b) list(str)
    • c) list.split(str)
    • d) all of the above
  40. What will print("Hello, " * 3) output?
    • a) Hello, Hello, Hello,
    • b) Hello, Hello, Hello
    • c) Hello Hello Hello
    • d) Hello, , Hello, , Hello,
  41. Which symbol is used for floor division in Python?
    • a) /
    • b) //
    • c) \
    • d) .
  42. What will the following code print? print(["Python", "is", "fun"][1])
    • a) Python
    • b) is
    • c) fun
    • d) Error
  43. What type of loop executes at least once?
    • a) for loop
    • b) while loop
    • c) do-while loop
    • d) infinite loop
  44. Which of these is NOT a valid variable name in Python?
    • a) my_variable
    • b) 2nd_variable
    • c) variable2
    • d) myVariable
  45. How do you define a method inside a class?
    • a) Using def keyword
    • b) Using method keyword
    • c) Using function keyword
    • d) Methods cannot be defined in a class
  46. What is the result of the following code? print([1, 2, 3] + [4, 5, 6])
    • a) [1, 2, 3, 4, 5, 6]
    • b) [1, 2, 3] + [4, 5, 6]
    • c) [4, 5, 6, 1, 2, 3]
    • d) Error
  47. Which built-in Python function can be used to iterate over a sequence?
    • a) loop()
    • b) iterate()
    • c) for()
    • d) None of the above
  48. How do you declare a global variable in Python?
    • a) global variable_name
    • b) declare variable_name
    • c) var variable_name
    • d) set variable_name
  49. What will be the output of print(type([1, 2, 3]))?
    • a) list
    • b) array
    • c) dict
    • d) tuple
  50. Which of the following is used to define a generator in Python?
    • a) yield
    • b) return
    • c) generate
    • d) all of the above