[bug] Python variable and list copy

This article refers to https://www.cnblogs.com/ifantastic/p/3811145.html

Correct

a = [1,2,3]

b = a

Have:

 

This is because a is not a list, it just points to a label on the list .

Really copy the variable method:

b = a [:] # complete slice

or 

b = list(a)

The results obtained by the above methods are as follows:

 

Get it in seconds.

I haven't encountered this problem until today, and the basic skills of programming are still too poor. Practice more in the future.

Guess you like

Origin www.cnblogs.com/ljfl-study/p/12687518.html