PCAP-31-03 Exam QuestionsBrowse all questions from this exam

PCAP-31-03 Exam - Question 11


What is the expected behavior of the following code?

Show Answer
Correct Answer: D

In the provided code snippet, my_list is defined as [1, 2, 3], meaning it has indices 0, 1, and 2. The code then attempts to assign the value of my_list[2] (which is 3) to my_list[3]. However, index 3 is out of range for this list, causing an IndexError. Since the exception is caught in the except block, it will print the error message 'list assignment index out of range'.

Discussion

3 comments
Sign in to comment
kstrOption: D
Jun 5, 2024

D tested: my_list = [1, 2, 3] try: my_list[3] = my_list[2] except BaseException as error: print(error)

DKAT2023Option: D
Jun 28, 2024

D is the correct

Dave304409Option: D
Jul 2, 2024

D is correct