Declaring a class with method 'print' with param 'self':
class First:
def print(self):
print('working')
return 2
Trying to call the method without instantiating the class:
First.print()
getting below message:
TypeError: print() missing 1 required positional argument: 'self'
Now when instantiating the class and accessing the method: it's working.
first = First()
first.print()
# working
# 2
Now defining the same class without any param in method print
:
class First:
def print():
print('working')
return 2
Calling the same method without instantiating the class and it's working:
First.print()
# working
# 2
Without defining the method param, python method behaving like Static. Is it true or something else?