How this code works? Although the column is not defined in nested list then how thee value gets changed? How 4th line of code works even if we have everything in a row in nested list?
a=["a", "1"]
b=["b", "2"]
c=[a,b]
c[0][1]="m"
print(f"{a}\n{b}")
How this code works? Although the column is not defined in nested list then how thee value gets changed? How 4th line of code works even if we have everything in a row in nested list?
a=["a", "1"]
b=["b", "2"]
c=[a,b]
c[0][1]="m"
print(f"{a}\n{b}")
Here is an understanding how the python code works,
In [1]: a=["a", "1"]
...: b=["b", "2"]
...: c=[a,b]
In [2]: c
Out[2]: [['a', '1'], ['b', '2']]
In [3]: id(c[0])
Out[3]: 4609196992
In [4]: id(a)
Out[4]: 4609196992
In [5]: id(a) == id(c[0])
Out[5]: True
c
is a list of list with a
and b
. So when you change c[0]
it's change a
as well.
Read about id()