• 13
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

In Python, None evaluates to less than zero? [duplicate]

See the manual:

Objects of different types, except different numeric types and different string types, never compare equal; such objects are ordered consistently but arbitrarily (so that sorting a heterogeneous array yields a consistent result).

and

CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.

  • 15
Reply Report

From the docs:

CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.

NoneType compares as smaller than int since the comparison appears to be case-sensitive.

>>> type(0)
<type 'int'>
>>> type(None)
<type 'NoneType'>
>>> 'NoneType' < 'int'
True
  • 4
Reply Report
    • @NullUserException: Interesting. That would seem to contradict the documentation, unless I'm missing something.
      • 2
    • @NullUserException: type(5) > type({}) gives false, so that part is consistent, though I'm not sure why they compare that way when, as you said, int > dict. However, type(None) > type(0). Hmm....
    • @NullUserException @hammar - I get int < dict here, on Python 2.6.6. But also the inconsistent type(None) > type(0) but None < 0...

It is intentional to make operations like sorting and dictionary comparison well defined.

[citing from the Language Reference]

The operators <, >, ==, >=, <=, and != compare the values of two objects. The objects need not have the same type. If both are numbers, they are converted to a common type. Otherwise, objects of different types always compare unequal, and are ordered consistently but arbitrary.

  • 3
Reply Report

Trending Tags