0

Whats wrong with writing it like this?

class X : def __init__(self): self.a = [] self.b = [] self.c = [] Should it instead be: class X : def __init__(self, a, b, c): self.a = [] self.b = [] self.c = [] ???

14th Apr 2022, 12:44 AM
Lenoname
3 Answers
+ 1
It won't work like this. You should initialize a class first unless. In your case, try x = X() x.a.append(something)
14th Apr 2022, 6:34 AM
Yuming Chen
0
The first one takes no arguments when initialize an instance X while the second one needs a, b, c. If not, the second one will raise errors. Which one to use depends on your practical situations.
14th Apr 2022, 1:16 AM
Yuming Chen
0
Yuming Chen In this case : class X : def __init__(self): self.a = [] self.b = [] self.c = [] If i want to append to a, does X.a.append() work?
14th Apr 2022, 1:22 AM
Lenoname