A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

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.

  • This Question is Closed
  1. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  2. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for your explanation. I now understand how the things relate to each other and what they mean.

  3. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  4. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Sorry, link should be http://docs.python.org/reference/datamodel.html

  5. anonymous
    • 5 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks for the reference, just what I needed to get a better understanding of lecture 15.

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

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.