Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我做:
cand = [ [ 0, 0 ] ] * 4
其次是:
cand[0][0] = 99
我得到:
[[99, 0], [99, 0], [99, 0], [99, 0]]
乘法是否只是复制列表引用?有没有办法有不同的列表?
它创建了对同一对象的四个引用。为了解决这个问题,您必须创建四个单独的列表:
cand = [[0, 0] for _ in range(4)]