MCQs on Python Keywords

  1. Which of the following is not a Python keyword?
    a) and
    b) try
    c) exception
    d) class
    Ans: c) exception
  2. What does the Python keyword “lambda” do?
    a) creates a new function
    b) defines a loop
    c) raises an exception
    d) defines a class
    Ans: a) creates a new function
  3. What is the purpose of the Python keyword “yield”?
    a) defines a variable
    b) creates a new object
    c) returns a value from a function
    d) defines a loop
    Ans: c) returns a value from a function
  4. Which Python keyword is used to define a block of code?
    a) for
    b) if
    c) while
    d) def
    Ans: d) def
  5. Which Python keyword is used to define a branching statement?
    a) for
    b) if
    c) while
    d) def
    Ans: b) if
  6. What is the Python keyword “global” used for?
    a) to define a variable outside of a function
    b) to define a variable inside of a function
    c) to define a function inside of a class
    d) to define a class outside of a module
    Ans: b) to define a variable inside of a function
  7. Which Python keyword is used to define a loop that iterates over a sequence?
    a) for
    b) if
    c) while
    d) def
    Ans: a) for
  8. Which Python keyword is used to stop a loop prematurely?
    a) continue
    b) break
    c) pass
    d) yield
    Ans: b) break
  9. Which Python keyword is used to define a function?
    a) for
    b) if
    c) while
    d) def
    Ans: d) def
  10. Which Python keyword is used to define a logical operator that returns true if either of its operands is true?
    a) not
    b) and
    c) or
    d) xor
    Ans: c) or
  11. Which of the following is a Python keyword?
    a) for
    b) foreach
    |c) repeat
    d) do
    Answer: a) for
  12. Which of the following is a Python keyword?
    a) start
    b) begin
    c) in
    d) process
    Answer: c) in
  13. Which of the following is a Python keyword used for defining a function?
    a) def
    b) fun
    c) func
    d) function
    Answer: a) def
  14. Which of the following is a Python keyword used for conditional statements?
    a) case
    b) if
    c) switch
    d) when
    Answer: b) if
  15. Which of the following is a Python keyword used for defining a class?
    a) class
    b) def
    c) function
    d) module
    Answer: a) class
  16. Which of the following is a Python keyword used for defining a counting loop?
    a) for
    b) loop
    c) iterate
    d) while
    Answer: a) for
  17. Which of the following is a Python keyword used for defining a variable?
    a) var
    b) let
    c) const
    d) all of the above
    Answer: d) all of the above
  18. Which of the following is a Python keyword used for importing modules?
    a) require
    b) from
    c) import
    d) include
    Answer: c) import
  19. Which of the following is a Python keyword used for exiting a loop?
    a) exit
    b) end
    c) break
    d) continue
    Answer: c) break
  20. Which of the following is a Python keyword used for continuing a loop?
    a) skip
    b) end
    c) break
    d) continue
    Answer: d) continue
  21. Which of the following is a Python keyword used for defining a try-except block?
    a) catch
    b) except
    c) try
    d) both b and c
    Answer: d) both b and c
  22. Which of the following is a Python keyword used for defining a dictionary?
    a) map
    b) dict
    c) set
    d) hash
    Answer: b) dict
  23. Which of the following is a Python keyword used for defining a list?
    a) array
    b) list
    c) tuple
    d) set
    Answer: b) list
  24. Which of the following is a Python keyword used for defining a set?
    a) map
    b) dict
    c) set
    d) hash
    Answer: c) set
  25. Which of the following is a Python keyword used for defining a tuple?
    a) array
    b) list
    c) tuple
    d) set
    Answer: c) tuple
  26. Which of the following is a Python keyword used for defining a generator?
    a) def
    b) generator
    c) yield
    d) return
    Answer: c) yield
  27. Which of the following is a Python keyword used for defining an iterator?
    a) def
    b) iterator
    c) yield
    d) return
    Answer: c) yield
  28. Which of the following is a Python keyword used for defining a lambda function?
    a) func
    b) lambda
    c) def
    d) function
    Answer: b) lambda
  29. Which of the following is a Python keyword used for defining a module?
    a) library
    b) package
    c) module
    d) import
    Answer: c) module
  30. Which of the following is a Python keyword used for defining a namespace?
    a) namespace
    b) package
    c) module
    d) import
    Answer: d) import
  31. Which of the following is a Python keyword used for defining a function?
    a) define
    b) def
    c) function
    d) func
    Answer: b) def
  32. Which of the following is a Python keyword used for creating a class?
    a) class
    b) new
    c) create
    d) instance
    Answer: a) class
  33. Which of the following is a Python keyword used for conditional branching?
    a) case
    b) switch
    c) if
    d) when
    Answer: c) if
  34. Which of the following is a Python keyword used for looping over a sequence of items?
    a) while
    b) until
    c) foreach
    d) for
    Answer: d) for
  35. Which of the following is a Python keyword used for breaking out of a loop?
    a) halt
    b) stop
    c) break
    d) exit
    Answer: c) break
  36. Which of the following is a Python keyword used for continuing to the next iteration of a loop?
    a) skip
    b) next
    c) continue
    d) go
    Answer: c) continue
  37. Which of the following is a Python keyword used for defining a block of code to be executed in an exception handling context?
    a) try
    b) except
    c) catch
    d) handle
    Answer: a) try
  38. Which of the following is a Python keyword used for specifying a block of code to be executed when an exception is raised?
    a) try
    b) except
    c) catch
    d) handle
    Answer: b) except
  39. Which of the following is a Python keyword used for defining a block of code to be executed regardless of whether an exception has been raised or not?
    a) try
    b) except
    c) finally
    d) always
    Answer: c) finally
  40. Which of the following is a Python keyword used for defining a variable with a constant value?
    a) const
    b) var
    c) let
    d) None of the above
    Answer: d) None of the above
  41. Which of the following is a Python keyword used for defining a function that returns a value?
    a) return
    b) yield
    c) continue
    d) break
    Answer: a) return
  42. Which of the following is a Python keyword used for defining a function that doesn’t return a value?
    a) return
    b) yield
    c) continue
    d) None of the above
    Answer: d) None of the above
  43. Which of the following is a Python keyword used for defining a function with default arguments?
    a) default
    b) def
    c) function
    d) None of the above
    Answer: b) def
  44. Which of the following is a Python keyword used for defining a function with variable-length arguments?
    a) vararg
    b) args
    c) kwargs
    d) None of the above
    Answer: b) args
  45. Which of the following is a Python keyword used for defining a function with keyword arguments?
    a) kwargs
    b) args
    c) vararg
    d) None of the above
    Answer: a) kwargs
  46. Which of the following is a Python keyword used for defining a function with both variable-length and keyword arguments?
    a) args
    b) kwargs
    c) vararg
    d) None of the above
    Answer: c) vararg
  47. Which of the following is a Python keyword used for defining a function that accepts any number of arguments?
    a) varargs
    b) args
    c) kwargs
    d) None of the above
    Answer: a) varargs
  48. Which of the following is a Python keyword used for defining a context manager?
    a) context
    b) with
    c) yield
    d) None of the above
    Answer: b) with
  49. Which of the following is a Python keyword used for defining a decorator function?
    a) decorator
    b) wrapper
    c) decorate
    d) None of the above
    Answer: d) None of the above (decorators are defined using the @ symbol)
  50. Which of the following is a Python keyword used for defining a loop that executes until a certain condition is met?
    a) while
    b) for
    c) if
    d) None of the above
    Answer: a) while
error: You can only copy the programs code and output from this website. You are not allowed to copy anything else.