Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Basic Object-Oriented Python Welcome to OOP Methods

Pedro Leitao
Pedro Leitao
1,615 Points

"Return False" x " = False"

Why in this case you define the boolean value with "return False"?

def use_gas(self):
    self.gas -= 50
    if self.gas <= 0:
        return False
    else:
        return True

While in this case you use "self.is_moving = False"

def stop(self):
    if self.is_moving:
        print('The car has stopped.')
        self.is_moving = False
    else:
        print('The car has already stopped.')

Thank You!

1 Answer

Steven Parker
Steven Parker
231,236 Points

These function are doing different kinds of things.

Notice that for the use_gas function, the value is being passed back to the caller, so it's part of a return statement.

But for stop, no value is being returned. Instead, the internal value is_moving is being tested; and also changed if needed.