current position:Home>Why does it show a running error

Why does it show a running error

2022-02-04 17:03:45 CSDN Q & A


《Python Programming from entry to practice 》 Chapter 9... Of classes 9.1 I don't understand why the operation failed , The following is my imitation of what I typed in the book , Is it right? snip I misunderstood there ?


Take the answer :

You wrote it. init function , There is an additional horizontal bar in the underline on the right , It's obviously asymmetric with the left side .
There is no need to name the initialization function according to the specification , The compiler does not consider it the default initialization function with parameters , It's a custom function .

Other answers 2:

You define Dog Class has no parameters .

Other answers 3:

I don't see what's wrong with your program , Tested once , The normal operation , Can you see the difference between mine and yours weixin_34319374

class Dog():    def __init__(self, name=None, age=None):        self.age=age    def sit(self):        print("is now sittingg.")    def roll_over(self):        print('roll over')

If it helps, please adopt it , Continue to communicate if there are problems , Your adoption is the greatest affirmation and motivation for my answer

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended