Is it possible to append to a in this case?And how | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is it possible to append to a in this case?And how

class X : def __init__(self): self.a = [] self.b = [] self.c = [] X.a.append(1) wont work

14th Apr 2022, 1:58 AM
Lenoname
2 Answers
+ 5
Make <a>, <b> and <c> become class member, define them in global space class X: a = [] b = [] c = [] for i in range( 1, 43 ): X.a.append( i ) print(X.a) (Edit) You already have the answer in your earlier post https://www.sololearn.com/Discuss/3017234/?ref=app
14th Apr 2022, 2:37 AM
Ipang
+ 2
In this case you have to instantiate an X object first: x = X() x.a.append()
14th Apr 2022, 2:34 AM
Simon Sauter
Simon Sauter - avatar