distinction between float & int

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ishwor

    #1

    distinction between float & int

    hi all,
    can anyone tell me why this distinction? i mean why it returns False
    on floats??[color=blue][color=green][color=darkred]
    >>> a = 1
    >>> b = 1
    >>> a is b[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> a = 1.1
    >>> b = 1.1
    >>> a is b[/color][/color][/color]
    False[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    thanx .
    --
    cheers,
    Ishwor Gurung
  • Steve Holden

    #2
    Re: distinction between float & int

    Ishwor wrote:
    [color=blue]
    > hi all,
    > can anyone tell me why this distinction? i mean why it returns False
    > on floats??
    >[color=green][color=darkred]
    >>>>a = 1
    >>>>b = 1
    >>>>a is b[/color][/color]
    >
    > True
    >[color=green][color=darkred]
    >>>>a = 1.1
    >>>>b = 1.1
    >>>>a is b[/color][/color]
    >
    > False
    >
    >
    > thanx .[/color]

    There is no guarantee that this will hold in all implementations of Python.

    The majority implementation, usually called CPython because its
    implementation language is C, keeps copies of the first 100 (?) integers
    so it doesn't have to create separate integer objects each time they are
    required.

    No caching at all is applied to floats, as far as I can tell.
    [color=blue][color=green][color=darkred]
    >>> a = 250
    >>> b = 250
    >>> a is b[/color][/color][/color]
    False

    regards
    Steve

    --


    Holden Web LLC +1 800 494 3119

    Comment

    Working...