Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
29
15
94
13.7K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: (A) 20 The code demonstrates how variable assignment works with mutable objects (like lists) in Python. a = [10, 20, 30] creates a list object [10, 20, 30] and assigns the variable a to reference this object in memory. b = a does not create a new list.
English
1
0
9
991
Sergei Kotov
Sergei Kotov@kotov_dev·
@PythonPr Answer: A) 20 Step by step: › a = [10, 20, 30] creates list › b = a makes b point to same list › a = [40, 50] reassigns a to NEW list (b unchanged!) › b still points to [10, 20, 30] › b[1] = 20 For beginners: Reassignment breaks the connection between variables!
English
1
0
7
835
Kamal Gurjar
Kamal Gurjar@KamalGurjar8·
@PythonPr Output A) 20 b = a makes b reference the original list [10, 20, 30]. Reassigning a to [40, 50] creates a new list and doesn’t affect b. So b[1] is still 20.
English
0
0
6
922
ANKIT 𓃱
ANKIT 𓃱@A9kitSingh·
@PythonPr A) 20 b = a makes b reference the original list [10, 20, 30]. When a is later reassigned to a new list [40, 50], b still points to the old list. So b[1] is 20.
English
0
0
1
596
Biel Men
Biel Men@BielMenHaha·
@PythonPr It's 20, because list a now is another list in another memory address while b points to the older one.
English
0
0
0
52
Teilen