Using a class as a data container

前端 未结 12 1117
孤街浪徒
孤街浪徒 2020-12-02 10:01

Sometimes it makes sense to cluster related data together. I tend to do so with a dict, e.g.,

self.group = dict(a=1, b=2, c=3)
print self.group[\'a\']
         


        
12条回答
  •  佛祖请我去吃肉
    2020-12-02 10:33

    In a language which supports it, I would use a struct. A dictionary would be closest to a structure in Python, at least as far as I see it.

    Not to mention, you could add a method to a dictionary anyway if you really wanted to ;)

提交回复
热议问题