一般来说我们很少使用 AddrBookEntry.__init__(name, phone) 这种方式来调用父类的构造器,因为 Python 支持多继承,所以我们希望可以有方法让子类自动的找到父类,这个方法就是 super() . In [33]: class EmpAddressBookEntry(AddrBookEntry): ...: "Employee address book entry class" ...: ...: def _...
我是新来的python OOP。我试图创建一个方法,获取用户的输入(书名、作者和流派),创建一个book对象,并仅在不存在此类书籍的情况下将其添加到列表中。起初,我想使用__eq__,但找不到一种方法让它工作。。。 这是我的代码: class Book: def __init__(self, book_name, author_name, genre): self.book_nam...
object is a special class in that it has the methods that are common to all Python classes, and it doesn't allow you to set any attributes on it. Let's see how we can access a base class from within a class. oop/super.duplication.py class Book: def __init__(self, title, publis...
We will see that this is almost natural in Python because we have a copy feature that helps greatly in using this technique. Useful when we have an existing object that needs to stay untouched, and we want to create an exact copy of it, allowing changes in some parts of the copy. ...