Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

150 Best Beginner-Level Python MCQs

  1. Which of the following is used to create a list of numbers from 0 to 10 in steps of 0.5 in Python?
    a) [x * 0.5 for x in range(21)]
    b) [x * 0.5 for x in range(20)]
    c) [x * 0.5 for x in range(0, 21)]
    d) [x * 0.5 for x in range(0, 20)]
    Correct Answer: a) [x * 0.5 for x in range(21)]
  2. What is the output of print("Python".split("t"))?
    a) [‘Py’, ‘hon’]
    b) [‘Pyt’, ‘hon’]
    c) [‘P’, ‘ython’]
    d) Error
    Correct Answer: a) [‘Py’, ‘hon’]
  3. Which of the following is used to create a list of squares of numbers from 1 to 10 in Python?
    a) [x ** 2 for x in range(1, 11)]
    b) [x ** 2 for x in range(1, 10)]
    c) [x ** 2 for x in range(11)]
    d) [x ** 2 for x in range(10)]
    Correct Answer: a) [x ** 2 for x in range(1, 11)]
  4. What is the output of print("Python".rsplit("t"))?
    a) [‘Py’, ‘hon’]
    b) [‘Pyt’, ‘hon’]
    c) [‘P’, ‘ython’]
    d) Error
    Correct Answer: a) [‘Py’, ‘hon’]
  5. Which of the following is used to create a list of cubes of numbers from 1 to 10 in Python?
    a) [x ** 3 for x in range(1, 11)]
    b) [x ** 3 for x in range(1, 10)]
    c) [x ** 3 for x in range(11)]
    d) [x ** 3 for x in range(10)]
    Correct Answer: a) [x ** 3 for x in range(1, 11)]
  6. What is the output of print("Python".split("t", 1))?
    a) [‘Py’, ‘hon’]
    b) [‘Pyt’, ‘hon’]
    c) [‘P’, ‘ython’]
    d) Error
    Correct Answer: a) [‘Py’, ‘hon’]
  7. Which of the following is used to create a list of even squares of numbers from 1 to 10 in Python?
    a) [x ** 2 for x in range(1, 11) if x % 2 == 0]
    b) [x ** 2 for x in range(1, 10) if x % 2 == 0]
    c) [x ** 2 for x in range(11) if x % 2 == 0]
    d) [x ** 2 for x in range(10) if x % 2 == 0]
    Correct Answer: a) [x ** 2 for x in range(1, 11) if x % 2 == 0]
  8. What is the output of print("Python".rsplit("t", 1))?
    a) [‘Py’, ‘hon’]
    b) [‘Pyt’, ‘hon’]
    c) [‘P’, ‘ython’]
    d) Error
    Correct Answer: a) [‘Py’, ‘hon’]
  9. Which of the following is used to create a list of odd cubes of numbers from 1 to 10 in Python?
    a) [x ** 3 for x in range(1, 11) if x % 2 != 0]
    b) [x ** 3 for x in range(1, 10) if x % 2 != 0]
    c) [x ** 3 for x in range(11) if x % 2 != 0]
    d) [x ** 3 for x in range(10) if x % 2 != 0]
    Correct Answer: a) [x ** 3 for x in range(1, 11) if x % 2 != 0]
  10. What is the output of print("Python".split("t", 0))?
    a) [‘Python’]
    b) [‘P’, ‘ython’]
    c) [‘Py’, ‘hon’]
    d) Error
    Correct Answer: a) [‘Python’]
  11. Which of the following is used to create a list of numbers from 0 to 10 in steps of 2 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))
  12. What is the output of print("Python".rsplit("t", 0))?
    a) [‘Python’]
    b) [‘P’, ‘ython’]
    c) [‘Py’, ‘hon’]
    d) Error
    Correct Answer: a) [‘Python’]
  13. Which of the following is used to create a list of numbers from 10 to 0 in steps of -1 in Python?
    a) list(range(10, -1, -1))
    b) list(range(10, 0, -1))
    c) list(range(10, -1))
    d) list(range(10, 0))
    Correct Answer: a) list(range(10, -1, -1))
  14. What is the output of print("Python".split("t", -1))?
    a) [‘Py’, ‘hon’]
    b) [‘Pyt’, ‘hon’]
    c) [‘P’, ‘ython’]
    d) Error
    Correct Answer: a) [‘Py’, ‘hon’]
  15. Which of the following is used to create a list of numbers from 0 to 10 in steps of 0.1 in Python?
    a) [x * 0.1 for x in range(101)]
    b) [x * 0.1 for x in range(100)]
    c) [x * 0.1 for x in range(0, 101)]
    d) [x * 0.1 for x in range(0, 100)]
    Correct Answer: a) [x * 0.1 for x in range(101)]

x
Advertisements
Advertisements