*EVERYTHING* is an object in Python

February 22, 2007

A recent (and very well-written) Ruby tutorial made the oft-repeated assertion that not everything in Python is an object. This is flatly untrue, as a brief look through the console will show you:

>>> someNumber = 1

>>> isinstance(someNumber, object)

That evaluates to True.

I think that settles the matter.

Entry Filed under: code. .

5 Comments

  • 1. Koz  |  February 22, 2007 at 10:00 pm

    >>> 1.abs
    File “”, line 1
    1.abs
    ^
    SyntaxError: invalid syntax

    That settles it further ;)

  • 2. Chris Ryland  |  February 25, 2007 at 7:31 pm

    Try

    >>> 1 .abs()
    Traceback (most recent call last):
    File “”, line 1, in ?
    AttributeError: ‘int’ object has no attribute ‘abs’

    So if numbers had an abs() method, you could call it that way. (Needs the space to disambiguate.)

  • 3. Patrick Thomson  |  February 25, 2007 at 8:53 pm

    Backing up Chris:

    1 .__abs__() works.

  • 4. Ben  |  March 25, 2007 at 11:56 am

    >>> abs(-1).+(1)
    File “”, line 1
    abs(-1).+(1)
    ^
    SyntaxError: invalid syntax
    >>> 1.+(1)
    2.0

  • 5. Armin Ronacher  |  May 10, 2007 at 5:24 pm

    >>> (-1).__abs__()
    1


About Me



I'm Patrick Thomson. I'm a sophomore at George Washington University, passionate about technology, Apple, and programming in Cocoa, Python, Ruby, and Nu.

Why "important shock"? It's an anagram of my name.

Meta

Blogroll

a

Top Posts

Blog Stats