[Tutor] Output reason

Gursimran Maken gursimran.maken at gmail.com
Fri Jul 12 10:24:39 EDT 2019


Hi,

Can someone please explain me the reason for below output.

Program:
def fun(n,li = []):
    a = list(range(5))
    li.append(a)
    print(li)

fun(4)
fun(5,[7,8,9])
fun(4,[7,8,9])
fun(5) # reason for output (why am I getting to values in this output.)

Output:
[[0, 1, 2, 3, 4]]
[7, 8, 9, [0, 1, 2, 3, 4]]
[7, 8, 9, [0, 1, 2, 3, 4]]
[[0, 1, 2, 3, 4], [0, 1, 2, 3, 4]]

Thank you,
Gursimran


More information about the Tutor mailing list