Initialize a list of objects in Python

前端 未结 4 1738
再見小時候
再見小時候 2021-02-04 03:49

I\'m a looking to initialize an array/list of objects that are not empty -- the class constructor generates data. In C++ and Java I would do something like this:



        
4条回答
  •  一整个雨季
    2021-02-04 04:05

    lst = [Object() for i in range(100)]
    

    Since an array is it's own first class object in python I think this is the only way to get what you're looking for. * does something crazy.

提交回复
热议问题