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

Andras Andras
Andras Andras
7,941 Points

sneaky and light_level

Hello,

Can you help me understand why in "return self.sneaky and light_level" the self.sneaky does not appear but light_level is printed.

import random

class Thief: sneaky = True def pickpocket(self): if self.sneaky: return bool (random.randint(0,1)) #return False def hide(self, light_level): return self.sneaky and light_level

1 Answer

Henrik Christensen
seal-mask
.a{fill-rule:evenodd;}techdegree
Henrik Christensen
Python Web Development Techdegree Student 38,322 Points

return self.sneaky and light_level - this just mean that the method will return True if both self.sneaky AND light_level are True or 'truthy'.

If one of them is False or 'falsy' then the method will return False

Andras Andras
Andras Andras
7,941 Points

Thank you, Henrik.