Python list append causes strange result

前端 未结 5 1314
执念已碎
执念已碎 2021-01-29 00:55

I have really strange problem. Here is the sample code:

class SomeClass(object):
    a = []
    b = []
    def __init__(self, *args, **kwargs):
        self.a =          


        
5条回答
  •  太阳男子
    2021-01-29 01:54

    dicts in python share the same memory space when you assign them to each other.

    for more information on this see: http://henry.precheur.org/python/copy_list

提交回复
热议问题