0
What is the difference between a=list and a=list[:]
Both of them are giving me a different output..in this case... U can try by removing or adding [:] https://code.sololearn.com/cT6ryN1RrlxK/?ref=app
4 ответов
+ 4
a = [1, 2, 3]
b = a
c = a[:]
b is the same list as a, which means you just gave it a different name, if you change elements in b, they will be changed in a too, as they are one single list with two different names.
c is just a part of a, and in this case the whole list, but it is independent, operations that you make on c won't affect a.
+ 3
Hahah once I spent an hour trying to figure out what was wrong with my code, untill I realized it! Happy to help!
+ 1
Aymane Boukrouh That was a new knowledge for me! I never know changing the values of a effect b since b is a different variable.
+ 1
Thnx! And doubt solved