首页 > 解决方案 > TypeError: __init__() 接受 3 个位置参数,但给了 4 个错误

问题描述

from abc import ABCMeta, abstractmethod
class Book(object, metaclass=ABCMeta):
    def __init__(self,title,author):
        self.title=title
        self.author=author   
    @abstractmethod
    def display(): pass
class MyBook(Book):
    def __innit__(self,title,author,price):
        self.title = title
        self.author = author
        self.price = price    
    def display(self):
        print("Title: {0}".format(self.title))
        print("Author: {0}".format(self.author))
        print("Price: {0}".format(self.price))
title=input()
author=input()
price=int(input())
new_novel = MyBook(title,author,price)
new_novel.display()

遇到错误:TypeError: init () 接受 3 个位置参数,但给出了 4 个,请给我有关如何修复此错误的想法

标签: python-3.xtypeerrorabstract-class

解决方案


您的第二个启动器函数中有错字。在 MyBook 类中将“ init ”替换为“ init ”。


推荐阅读