I'm trying to use a class, but I have this error:
TypeError: search() missing 1 required positional argument: 'self'
This is my code:
class School:
def search(self):
... # do some stuff
harva = School()
School.search()
Your final line is incorrect: you must (il faut que vous) invoke an instance method by calling it with an instance, not with the class:
harva.search()
When you call the method as a class method, it needs the instance:
School.search(harva)
However, you should use the first version.
In the future, don't write so much code at once. You should try to invoke the method before you have written all of that.
In object-oriented programming...the basic fundamental element is an object and a class along with its member variables & member functions can only be accessed through an instance of that class i.e again object.
class School():
def search(self):
...#some code
harva = School()
harva.search()
You can access a function inside a class without creating an instance of that class.
Such functions are called as static functions.
Ecoleis not defined; it's named as a class.