69.5k views
4 votes
What is the output of the following Python code?

x = ['bread', 20]
y = x
x.extend(['eggs', 50])
x[-1] = 70
print(y[-1])
A) 50
B) 70
C) 'eggs'
D) 20

User Nancyann
by
8.5k points

1 Answer

1 vote

Final answer:

The output of the given Python code is error.

Step-by-step explanation:

The output of the given Python code is error. The code is assigning the output of the xx.extend(['eggs', 50]) operation to the variable y, which would be None since the extend() method modifies the original list and returns None. Therefore, when we try to access y[-1], we get an error since y is None and None does not have an index.

User Btbenjamin
by
8.1k points