Skip to content

Use == instead of 'is' for comparing number #4

@progval

Description

@progval

Hi,

In this notebook: https://github.com/mikkokotila/jupyter4kids/blob/master/notebooks/numerical-computing-is-fun-2.ipynb you use the 'is' keyword to compare numbers.

This should be avoided, because Python's semantic does not guarantee that '1 is 1'. In fact, in the CPython implementation, this is only True for integers lower or equal to 256:

>>> a = 257
>>> b = 257
>>> a is b
False
>>> a = 256
>>> b = 256
>>> a is b
True

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions