The error occurs because you are trying to call the instance method of the PhoneBook directly from its class.
Classes in python are objects. Each class has its own namespace. All variables and functions that are declared in the class are in its namespace and can be accessed as attributes of the class object.
Functions defined in a class are available to class instances as methods.
Methods and functions have 2 important differences. Functions are not attached to any objects, no parameters are passed to them by themselves. Methods are always attached to an object (instance), the method always receives an instance of the class as its first parameter (usually referred to as self ).
When an instance of a class is created, all functions defined in the class become its methods.
Example:
class PhoneBook: #код PhoneBook print( PhoneBook.add_person ) # напечетает что это просто функция # лежащая в пространстве имен PhoneBook my_book = PhoneBook() print( my_book.add_person ) # напишет что это bound метод (не функция!) my_book.add_person(newcont, new_phone) # происходит вызов метода (первый параметр будет передан автоматически) # это эквивалентно следующему вызову PhoneBook.add_person(my_book, newcont, new_phone)
In your PhoneBook.add_person(newcont, new_phone) code PhoneBook.add_person(newcont, new_phone) you call a function with three parameters, but you pass it only 2 parameters. Because of this, you get an error.
selfparameter is passed automatically for class instances, this does not apply to the class itself. - Alex Krasspickle), so that you don’t get yourself confused while reading. And where doesdjango? - mkkik