Python Sample Quiz

a = [1,2,3]
b = a.copy()
print(a == b,a is b)

what is Out put

3 Likes

True False
will the output

2 Likes

Output:
True False

True False

A bit of explanation:

  • a == b compares the values of a and b. Since b is a copy of a, they have the same values [1, 2, 3], so the comparison a == b evaluates to True.

  • a is b checks if a and b refer to the same object in memory. Even though b is a copy of a, it creates a new object with the same values. Therefore, a is b evaluates to False because a and b are different objects in memory.

2 Likes