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 Python Collections (Retired) Lists Redux Combining Lists

When I type help(range) I get a lot of methods associated with range defined like __eq__. How to try them out?

What syntax is right to trying out these methods?

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

You can just call them, range(10).__eq__(range(10)) (since __eq__() takes a second item to compare the item it's called on with). Under the hood, this is what Python is actually doing when you dorange(10) == range(10). The==triggers therangeclass'seq` method. We'll be going into some of this in the next course, actually.

Generally, though, methods that start and end with __ are not meant to be called by your code. Python uses them internally for special features in the language, like comparison or printing or instantiation.