It’s not All Animals and Fruits BUG?


#1

My code is as below:

and it is wrong because


#2

Hi,

your last two lines shouldn't be inside of the cass definition.


#3

Thank you very much for kindly reply


#4

Hello,

I had the same problem as SUGARKAKA and you solved it.

Could you explain why this needs to be outside the class please?

Thank you.


#5

The class definiton is like a template for objects.

You can only create an object of a certain class if that class is already defined. If you try to create an instance of ShoppingCart inside of ShoppingCart's definition, Python doesn't know yet what ShoppingCart is, because it is still "reading" the definition.