0

So I was just trying to do the same basic classes example from python.org in my Python 3.7.0 IDLE (Shell), and when I tried to run this code:

class Giraffes:
    def _init_(self, spots):
        self.giraffe_spots = spots

gerald = Giraffes(100)

It gave me this error:

Traceback (most recent call last):
File "<pyshell#69>", line 1, in <module>
  gerald = Giraffes(100)
TypeError: Giraffes() takes no arguments

Doesn't the init function in class Giraffes make Gerald take parameter self?

1 Answer 1

1

The constructor method (like other Python magic methods) is called __init__ (two underscores on each side).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.