Q. What does the Python code: x = [1, 2, 3]; y = x; y[0] = 10; print(x) output?

A
[1, 2, 3]
B
[10, 2, 3]
C
[10, 1, 2]
D
Error
Solution:

Since y is an alias for x (same object), modifying y[0] also changes x[0], resulting in [10, 2, 3].

Entri PDF Icon

Get Question Bank

Strengthen Your Practice with our comprehensive question bank.

Entri Contact Image

Get Expert Advice for Free: Register for Your Free Consultation Now!