+ 1

Oops!!! python

class Example: def __init__(self): self.__num=10 @staticmethod def display(): self.__num+=1 print(self.__num) obj=Example() obj.display() who got it...and how??

13th May 2018, 4:55 PM
Rvk Dudes
Rvk Dudes - avatar
8 odpowiedzi
+ 6
ah sorry no, you just pass in vars
13th May 2018, 5:38 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
13th May 2018, 5:42 PM
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer - avatar
+ 3
Your not using the display method like a static method, but rather just a normal method. class Example: def __init__(self): self.__num=10 def display(self): self.__num+=1 print(self.__num) obj=Example() obj.display() a static method belongs to the class without access to class or instance variables and an instance of that class is not needed. the self keyword refers to the current instance of that class, therefore it shouldn't be used in a true static method.
13th May 2018, 5:44 PM
ChaoticDawg
ChaoticDawg - avatar
0
Can I use self in staticmethod?
13th May 2018, 5:34 PM
Rvk Dudes
Rvk Dudes - avatar
0
wht?? I didn't get your point
13th May 2018, 5:39 PM
Rvk Dudes
Rvk Dudes - avatar
0
What's the mistake I made here? ? is that the use of self ?
13th May 2018, 5:40 PM
Rvk Dudes
Rvk Dudes - avatar
0
thqq
13th May 2018, 5:43 PM
Rvk Dudes
Rvk Dudes - avatar
0
exactly. ..! This is the answer I need..Thank you
13th May 2018, 5:46 PM
Rvk Dudes
Rvk Dudes - avatar