πŸ“Š Python
Q. What will this code print?
Code:
a = [1, 2, 3]
b = a[:]
a.append(4)
print(b)
  • (A) [1, 2, 3, 4]
  • (B) [1, 2, 3]
  • (C) [4]
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) [1, 2, 3]

Explanation: Using slicing (`[:]`) creates a shallow copy of the list.

Explanation by: Mr. Dubey
Using slicing (`[:]`) creates a shallow copy of the list.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
50
Total Visits
πŸ“½οΈ
8 mo ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
84%
Success Rate