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 Object-Oriented Python Dice Roller Project Breakdown

What does the "or" do in self.value = value or random.rantint(1,sides)

In Kenneth's example, what does the "or" do there? it seems like it'd make a boolean comparison between value (in his examples is 0) and whatever random number got returned. Why not just have the random number generator return a value?

1 Answer

If value = 0, which it is initialized as, self.value will only be equal to random.rantint(1,sides). If, however, value is defined as nonzero then self.value = value, regardless of what random.rantint(1,sides) ends up being. Hope that helps.

oooh, ok, cool! Thank you!