“This constructor takes no arguments” error in __init__

前端 未结 3 1432
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 14:02

I\'m getting an error while running the following code:

class Person:
  def _init_(self, name):
    self.name = name

  def hello(self):
    print \'Initiali         


        
3条回答
  •  死守一世寂寞
    2020-12-01 14:35

    Use double underscores for __init__.

    class Person:
      def __init__(self, name):
    

    (All special methods in Python begin and end with double, not single, underscores.)

提交回复
热议问题