Python MCQs Test 4

Fill in your details and start your exam now!

1 / 20

What is the purpose of the break statement in a loop?

2 / 20

What does the reverse() method do in Python lists?

3 / 20

What is the output of the following code? \npython\nprint("python".upper())

4 / 20

Which of the following is the correct way to open a file named example.txt in Python for reading and writing?

5 / 20

What is the output of the following code? \npython\nx = [1, 2, 3]\nprint(x.pop())

6 / 20

What does the any() function do in Python?

7 / 20

What is the output of the following code? \npython\nprint("hello".index("l"))

8 / 20

Which of the following is NOT a valid way to define a function in Python?

9 / 20

What does the clear() method do in Python dictionaries?

10 / 20

What is the output of the following code? \npython\nprint(5 != 5)

11 / 20

What is the purpose of the pass statement in Python?

12 / 20

What does the update() method do in Python dictionaries?

13 / 20

What is the output of the following code? \npython\nprint("python".capitalize())

14 / 20

Which of the following is the correct way to open a file named example.txt in Python for appending?

15 / 20

What is the output of the following code? \npython\nx = [1, 2, 3]\nprint(x[1:2])

16 / 20

What does the isinstance() function do in Python?

17 / 20

What is the output of the following code? \npython\nx = 10\ny = 5\nprint(x // y)

18 / 20

Which of the following is NOT a valid way to iterate over a dictionary in Python?

19 / 20

What does the format() method do in Python?

20 / 20

What is the purpose of the finally block in a try-except statement in Python?

Your score is

The average score is 79%

0%

Scroll to Top