Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:10:40+00:00 2026-06-12T22:10:40+00:00

Hi I am overriding __cmp__ . If the second object passed is None ,

  • 0

Hi I am overriding __cmp__ . If the second object passed is None, or if it is not an instance of someClass, then it returns -1.

I don’t understand what exactly is happening here.

class someClass():
    def __cmp__(self, obj):
        if obj == None:
            return -1
        if not isinstance(obj, someClass):
            return -1  

My test function:

def test_function(self):  
        obj1 = someClass()
        self.assertTrue(obj1 < None)
        # I get true.
        self.assertTrue(obj1 > None)
        # I get failure as False is returned.

Could anyone please explain to me:

  • What are the return values?
  • How is it deciding whether it will return True or False when the comparison signs are changed?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:10:41+00:00Added an answer on June 12, 2026 at 10:10 pm

    When the obj is None, your program will return -1, while returning a negative integer means self < obj, so obj1 < None is True, and obj1 > None is false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just overriding Equals in TKey does not help. public override bool Equals(object obj) {
Overriding a new controller without 'new!' does not display ActiveAdmin layout. But then when
I understand overriding a method/function redefines its implementation in the derived class from its
Im overriding an equals() method and I need to know if the object is
This question demonstrates that overriding an Ember.View instance's didInsertElement allows you to execute some
I have an overriding Object class (Guide) with a subclass (Session). public class Guide
I know that overriding the back button functionality is not considered a good user
When overriding the equals() function of java.lang.Object, the javadocs suggest that, it is generally
I tried overriding __and__ , but that is for the & operator, not and
I am overriding a method which has an XmlReader being passed in, I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.