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
12
125
10.6K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: D Why!? The default value for the parameter b is a mutable object (a list). In Python, default arguments are evaluated only once when the function is defined, not each time the function is called. When func(1) is called the first time, b refers to the original list [],
English
0
0
0
440
Steve
Steve@chistev12·
@PythonPr D, a similar example was used in the official Python tutorial documentation
English
0
0
0
167
Daniel
Daniel@dan325·
@PythonPr I don’t know python, but it’s gotta be C, right? b is a local variable in ‘func’
English
0
0
0
17
Ahmad
Ahmad@chahmad____·
@PythonPr Isn’t the list b created in func (1) got destroyed after return so technically it would print [1] and then [2]
English
0
0
0
12
Bartosz Wesołowski
Bartosz Wesołowski@Tie0062·
@PythonPr Parameter A is 1 , parameter B is 2, so first, and second is [1,2] answer is with this D
English
0
0
0
63
Paylaş