subclass of integers

Roberto Bonvallet rbonvall at
Sun Sep 16 07:21:31 CEST 2007

On Sep 14, 10:30 am, Mark Morss <mfmo... at> wrote:
> I would like to construct a class that includes both the integers and
> None.  I desire that if x and y are elements of this class, and both
> are integers, then arithmetic operations between them, such as x+y,
> return the same result as integer addition.  However if either x or y
> is None, these operations return None.

No need to create a new class:

        result = a * b
    except TypeError:
        result = None

Roberto Bonvallet

More information about the Python-list mailing list