anonymous
  • anonymous
I just watched lecture 15 and wonder why p > q calls cPoint's __cmp__ function. I'd expect p > q check whether p's referent is greater than q's referent. For __cmp__ to be called I'd expect to use dot notation.
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
katieb
  • katieb
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
the functions that use the __functionname__ convention mostly deal with operator overloading--that is, how the + sign and other operators behave differently depending on whether you're working with strings, ints, or other data types. The __cmp__ function definition for a class defines how the instances of the class will be compared to each other in terms of >, <, and ==. It's kind of hard to see that with the cPoint data type because while __cmp__ is supposed to return different things depending on whether one value is greater than, equal to, or less than the other, it's hard as far as I know for one point to be meaninfully "greater than" or "less than" another.
anonymous
  • anonymous
Thanks for your explanation. I now understand how the things relate to each other and what they mean.
anonymous
  • anonymous
It would also be good to check out (http://docs.python.org/reference/datamodel.html). That also includes "rich comparison" methods, which are ways to control the behaviors of the individual comparison operators: < > == etc.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
Sorry, link should be http://docs.python.org/reference/datamodel.html
anonymous
  • anonymous
Thanks for the reference, just what I needed to get a better understanding of lecture 15.

Looking for something else?

Not the answer you are looking for? Search for more explanations.