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

Tuples, I want to know more about them so I use the python help(), I get this...

I get the first couple of lines, but from "Methods defined here" and on, I'm lost. Are they dunder init functions I will use? or are they the behind the scenes heavy lifting that python does.

 |  tuple() -> empty tuple
 |  tuple(iterable) -> tuple initialized from iterable's items
 |
 |  If the argument is a tuple, the return value is the same object.
 |
 |  Methods defined here:
 |
 |  __add__(self, value, /)
 |      Return self+value.
 |
 |  __contains__(self, key, /)
 |      Return key in self.
 |
 |  __eq__(self, value, /)
 |      Return self==value.
 |
 |  __ge__(self, value, /)
 |      Return self>=value.
 |
 |  __getattribute__(self, name, /)
 |      Return getattr(self, name).
 |
 |  __getitem__(self, key, /)
 |      Return self[key].
 |
 |  __getnewargs__(...)

1 Answer

They do the heavy lifting, so they are used by you the pythonista indirectly:

thirteen_one = (13, 1)
13 in thirteen_one
# returns True

In this case Python called contains(13, thirteen_one)

Dunder methods can be defined in custom classes to invoke certain behaviors when specific syntax is used. More info

Thanks Jonathin