Aug-30-2017, 02:49 AM
Today I meet this exercise:
What this code will output and why?
I expected to see 'd b c', but whet i run this program i was surprised. The output is [['d'], ['a', 'b', 'c'], ['a', 'b', 'c']].
Why is this code works this way?
What this code will output and why?
x = [[]]*3 x[0].append('a') x[1].append('b') x[2].append('c') x[0]=['d'] print(x)
I expected to see 'd b c', but whet i run this program i was surprised. The output is [['d'], ['a', 'b', 'c'], ['a', 'b', 'c']].
Why is this code works this way?