question about classes and variable | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

question about classes and variable

I want to make a class Foo . Foo has one input and I want to write a code if I dont use any parameter for that, the output will be 0. p = Foo() >>> print(p.x) 0 currently with this program: class Foo: x=0; def __init__(self, x): self.x=x I can get zero if I call p=Foo but not p= Foo(). Any idea how can i fix this

20th Apr 2018, 2:03 PM
Sagheb
Sagheb - avatar
1 Answer
+ 2
Did you try this? def __init__(self): self.x = 0
20th Apr 2018, 2:12 PM
Timon Paßlick