+ 1

What's the difference between a and b in these two python classes?

What is the difference between these? class A(): def __init__(self, a, b): self.a = a self.b = b VS class A(): a = 1 b = 1 def __init__(self, a, b): self.a = a self.b = b

22nd Oct 2020, 3:23 AM
Plutonian Fairy
Plutonian Fairy - avatar
2 Answers
+ 1
In the first case, self.a and self.b are instance variables. In the second case, a and b are class variables, and self.a and self.b are instance variable. There is a huge difference between instance variable and class variable.
22nd Oct 2020, 5:38 AM
Théophile
Théophile - avatar
0
Nothing different we just have same extra properties in above one along with constructor
22nd Oct 2020, 3:57 AM
Ayush Kumar
Ayush Kumar - avatar