Home > other > How to create multiple objects correctly?
How to create multiple objects correctly?
Time:10-22
In accordance with the following code, the output of the whole is 9, And want is every cycle to create an object to accommodate different data, ask how can create a new object in each loop?
The class Comment () : Def __init__ (self) : Pass
Def lop () : Comments=[] For I in range (10) : Comment=the comment The comment. Independence idx=I Comments. Append (comment)
The return comments
If __name__=="__main__ ': Comments=lop ()
# print (len (comments))
For independence idx in range (len (comments) : Print (comments) [r]. Independence idx independence idx)
CodePudding user response:
Why not add parentheses, instantiation of the object can be referenced again? !