What is the output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the output?

Class mycls: def__init__(self,a=0,b=0) self.a=a self.b=b @classmethod def value_a(cls,value): return cls (value*10) Obj=mycls(1,2).value_a(3) print(obj a,obj b)

16th Aug 2019, 4:42 AM
Raju Singh
Raju Singh - avatar
2 Answers
+ 4
30 0 class mycls: def __init__(self,a=0,b=0): self.a=a self.b=b @classmethod def value_a(cls,value): return cls (value*10)#equivalent to mycls(value*10),so you lost your self.b when using this class method obj=mycls(1,2).value_a(3) print(obj.a,obj.b)#obj.b has no value because you reset the obj btw,remember to not capitalised clasd,I have brushed up the codes a bit
16th Aug 2019, 4:52 AM
Hoh Shen Yien
Hoh Shen Yien - avatar
0
Thanks Shiny Star Noted
16th Aug 2019, 4:57 AM
Raju Singh
Raju Singh - avatar