class Student:
def __init__(self, name):
self.name = name
I know why self is used in this code. This can take different students and make differnt attributes
student1 = Student()
student2 = Student()
...
studentn = Student()
------------------------------------
student1.name
student2.name
...
studentn.name
but I can't understand why this code below needs self parameter.
class Student:
def study():
print("I'm studying")
Student().study()
output
Traceback (most recent call last):
File "C:/directory/test.py", line 12, in <module>
Student().study()
TypeError: study() takes 0 positional arguments but 1 was given