Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Object-Oriented Python Advanced Objects Double

Chiroi Niehus
Chiroi Niehus
6,729 Points

I Am Having Trouble on Code Challenge: Double Task 3 of 3

I am having trouble figuring out whether it should be self or int that I multiply by 2. Also, I'm not sure where to put the two separate lines of code - inside the function, or in the class. Please help!

class Double(int):
    def __new__(*args, **kwargs):
        self = int.__new__(*args, **kwargs)
        return self

    doubled_value = self * 2
    return doubled_value

1 Answer

Kamaren McCord
Kamaren McCord
11,209 Points

It looks like you want to put the code for the *double * inside of the new method. If you put it outside of this method the code will not be ran and thus will not return self * 2 when created.

self is an int so take self and multiply by 2, then return self.

also keep in mind that you cannot return code after a return has already been made. so you cannot use double return statements.