Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

150 Best Beginner-Level Python MCQs

  1. What is the output of print("Python".rjust(10, "*"))?
    a) Python
    b) Python

    c) Python
    d) Error
    Correct Answer: a) ****Python
  2. Which of the following is used to create a tuple comprehension in Python?
    a) (x for x in iterable)
    b) [x for x in iterable]
    c) {x for x in iterable}
    d) <x for x in iterable>
    Correct Answer: a) (x for x in iterable)
  3. What is the output of print("Python".center(10, "*"))?
    a) Python
    b) Python****
    c) ****Python
    d) Error
    Correct Answer: a) Python
  4. Which of the following is used to create a generator expression in Python?
    a) (x for x in iterable)
    b) [x for x in iterable]
    c) {x for x in iterable}
    d) <x for x in iterable>
    Correct Answer: a) (x for x in iterable)
  5. What is the output of print("Python".strip())?
    a) Python
    b) Python
    c) Python
    d) Error
    Correct Answer: a) Python
  6. Which of the following is used to create a list of numbers from 0 to 9 in Python?
    a) list(range(10))
    b) list(range(9))
    c) list(range(0, 10))
    d) list(range(0, 9))
    Correct Answer: a) list(range(10))
  7. What is the output of print("Python".lstrip())?
    a) Python
    b) Python
    c) Python
    d) Error
    Correct Answer: a) Python
  8. Which of the following is used to create a list of numbers from 1 to 10 in Python?
    a) list(range(1, 11))
    b) list(range(1, 10))
    c) list(range(10))
    d) list(range(11))
    Correct Answer: a) list(range(1, 11))
  9. What is the output of print("Python".rstrip())?
    a) Python
    b) Python
    c) Python
    d) Error
    Correct Answer: a) Python
  10. Which of the following is used to create a list of even numbers from 0 to 10 in Python?
    a) list(range(0, 11, 2))
    b) list(range(0, 10, 2))
    c) list(range(2, 11, 2))
    d) list(range(2, 10, 2))
    Correct Answer: a) list(range(0, 11, 2))
  11. What is the output of print("Python".partition("t"))?
    a) (‘Py’, ‘t’, ‘hon’)
    b) (‘Pyt’, ‘h’, ‘on’)
    c) (‘P’, ‘t’, ‘ython’)
    d) Error
    Correct Answer: a) (‘Py’, ‘t’, ‘hon’)
  12. Which of the following is used to create a list of odd numbers from 1 to 10 in Python?
    a) list(range(1, 11, 2))
    b) list(range(1, 10, 2))
    c) list(range(0, 11, 2))
    d) list(range(0, 10, 2))
    Correct Answer: a) list(range(1, 11, 2))
  13. What is the output of print("Python".rpartition("t"))?
    a) (‘Py’, ‘t’, ‘hon’)
    b) (‘Pyt’, ‘h’, ‘on’)
    c) (‘P’, ‘t’, ‘ython’)
    d) Error
    Correct Answer: a) (‘Py’, ‘t’, ‘hon’)
  14. Which of the following is used to create a list of numbers from 10 to 1 in Python?
    a) list(range(10, 0, -1))
    b) list(range(10, 1, -1))
    c) list(range(10, 0))
    d) list(range(10, 1))
    Correct Answer: a) list(range(10, 0, -1))
  15. What is the output of print("Python".splitlines())?
    a) [‘Python’]
    b) [‘P’, ‘y’, ‘t’, ‘h’, ‘o’, ‘n’]
    c) [‘P’, ‘ython’]
    d) Error
    Correct Answer: a) [‘Python’]

x
Advertisements
Advertisements