Post

Python Developer
Python Developer@Python_Dv·
Comment your answer now ⬇️
Python Developer tweet media
English
27
15
92
8.8K
PyBerry Tech 🐍🍓
PyBerry Tech 🐍🍓@PyBerryTech·
Option C : [1, 2, 3] [1, 2, 3, 4] Explanation👇 a = [1,2,3] creates a list. b = a[:] creates a copy of list `a` using slicing. Now `b` is a **separate list in memory. b.append(4) adds `4` only to `b`, not to `a`. Since `a` and `b` are different lists, modifying `b` does not affect `a`. Key point: `a[:]` makes a **shallow copy**, not a reference.
English
2
0
11
672
Earnest Codes
Earnest Codes@Earnesto037·
@Python_Dv Answer: (C) This problem tests the understanding of list copying in Python. Variable Assignment: The line a = [1, 2, 3] creates a list and assigns it to variable a. Slicing for Copy: The expression a[:] creates a shallow copy of the list a and assigns it to b. This
English
2
0
7
494
K.AMMAAR
K.AMMAAR@k_ammaar12·
@Python_Dv It is c because a is not appended it was b that was appended.
English
0
0
2
198
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@Python_Dv Answer: C. Slice [:] copies the list → a stays [1,2,3], b becomes [1,2,3,4].
English
0
0
1
309
KrunalSinh Sisodia
KrunalSinh Sisodia@krunalbuilds·
@Python_Dv output: 👉 [1, 2, 3] [1, 2, 3, 4] Reason? a[:] creates a shallow copy of the list. So b is a new list. Appending to b doesn’t affect a. b = a Then both would change. 😄 Copy vs reference. Classic Python interview trap.
English
0
0
1
131
Omo Yewa
Omo Yewa@AceKelm·
C. [1, 2, 3] [1, 2, 3, 4]. Two concepts are in play here. The first is the concept of slicing and the second one is the append method. b = a[ : ]. This means slice through "a" from the beginning to the end. Which gives [1, 2, 3]. b.append(4). Means add 4 to the existing values of b, but as the last element. This gives [1, 2, 3, 4]. So print(a, b) gives the answer.
English
0
0
1
96
Othieno Michael Edwards
Othieno Michael Edwards@EdwardsOthieno·
@Python_Dv 1. b = a[:] this type of assignment is an old fashioned way of copying. This means variable b is an separate memory from variable a. Changes made to variable b won't affect variable a 2. Output will be [1,2,3][1,2,3,4]
English
0
0
1
19
Jimmy Fikes
Jimmy Fikes@akajim·
@Python_Dv C. We have two lists in differtmemory locations. Only b is modified in place. So the result is[1,2,3] [1,2,3,4]
English
0
0
0
27
GAMBIT
GAMBIT@gambflash·
@Python_Dv And= C. appending affect only( b) not (a)
English
0
0
0
134
junaid.
junaid.@juniSpeaks·
@Python_Dv b = a[:] creates a 'shallow copy' of a. Now a and b share different memory and .append() outputs option 'C'. [:] is a slicing technique which copies everything from start to end. Unlike append(), slicing creates a brand new list without altering original list.
English
0
0
0
16
Bagikan