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
25
18
142
13.2K
Sergei Kotov
Sergei Kotov@kotov_dev·
a) [1, 2, 3] The gotcha: a = [4, 5, 6] creates a NEW list, it doesn't modify the original. So b still points to [1, 2, 3]. For beginners: If it was a[:] = [4, 5, 6], THEN b would change too. Reassignment vs mutation — key difference!
English
0
0
0
411
Othieno Michael Edwards
Othieno Michael Edwards@EdwardsOthieno·
@PythonPr 1. a = [1, 2, 3] a new list is created for variable a 2. b = a, this doesn't create a new list for variable b but rather references the list objects of var a 3. a = [4, 5, 6], a new list is created for Var a but variable b still references the original list 4. A. is the output
English
0
0
0
337
Popular Media - Online 🎥
Popular Media - Online 🎥@RooX1234esh·
B = 123456 for me. The real answer is where and what are you coding? It matters where you are coding and where the python script will be used. Maya Python code doesn't care what order the list is in. Who can tell I am an animator? If you're coding in python only and that's your only desire B = 123 (print b) but the answer is know your coding environment where you plan to use your code or you would get the incorrect output or an error
English
0
0
0
133
Nobody
Nobody@baddestbent·
@PythonPr A This is because the variable "b" refers to the original list of the variable "a"(which is the first one). The second list, which is also reassigned to the variable "a" doesn't have any effect on what the variable "b" is pointing to.
English
0
0
0
390
Diego Souza
Diego Souza@Diego_Souza_86·
@PythonPr How would it be if after a:456 we get a new line b=a?
English
0
0
0
48
StackDevFlow
StackDevFlow@stackdevflow·
@PythonPr Output? Chaos 😎… just kidding, need the code first
GIF
English
0
0
0
19
Paylaş