Python MCQs Test 5

Python MCQs Test 5

1 / 20

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

2 / 20

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

3 / 20

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

4 / 20

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

5 / 20

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

6 / 20

What does the enumerate() function do in Python?

7 / 20

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

8 / 20

Which of the following is NOT a valid way to remove an item from a list in Python?

9 / 20

What does the values() method return in Python dictionaries?

10 / 20

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

11 / 20

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

12 / 20

What does the min() function return in Python?

13 / 20

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

14 / 20

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

15 / 20

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

16 / 20

What does the keys() method return in Python dictionaries?

17 / 20

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

18 / 20

Which of the following is NOT a valid way to create a tuple in Python?

19 / 20

What does the del keyword do in Python?

20 / 20

What is the output of the following code? \npython\nx = "hello"\nprint(x[1])

Your score is

The average score is 85%

0%

Scroll to Top