Implicit Conversions

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

    Implicit Conversions

    I wanted to know the order of implicit conversions and which sort of values
    allow them. From searching around in books and the archive of this mailing
    list, it seems to be that only numbers are implicitly converted within each
    other and bools can be implicitly converted to ints? However, I'm unable to
    find any other implicit conversions and the order of the implicit
    conversions (something like int->float->long). Any help would be greatly
    apprectiated. Also, I'm not on the mailing list so can everyone please cc me
    in the replies?
    Reneé


  • Mel Wilson

    #2
    Re: Implicit Conversions

    In article <mailman.112.10 71251837.9307.p ython-list@python.org >,
    "=?iso-8859-1?B?UmVuZek=?=" <rlogan@hmc.edu > wrote:[color=blue]
    >I wanted to know the order of implicit conversions and which sort of =
    >values
    >allow them. From searching around in books and the archive of this =
    >mailing
    >list, it seems to be that only numbers are implicitly converted within =
    >each
    >other and bools can be implicitly converted to ints? However, I'm unable =
    >to
    >find any other implicit conversions and the order of the implicit
    >conversions (something like int->float->long). Any help would be greatly
    >apprectiated . Also, I'm not on the mailing list so can everyone please =
    >cc me
    >in the replies?[/color]

    Anybody?

    Speaking as a Python programmer (not a Python developer),
    I would say that Python doesn't generally do implicit
    conversions. The programmer keeps track of the types of the
    operands passed to operators and functions, and the
    operators and functions do what they can with what they get.

    You have it right that the arithemetic operators work so
    as not to lose "comprehensivit y": an operation on a complex
    yields a complex OR an operation on a float yields a float,
    OR an operation on a long yields a long OR the operation
    yields an int. (Those are Python short-circuiting OR's
    there.)

    Regards. Mel.

    Comment

    • Serge Orlov

      #3
      Re: Implicit Conversions


      "Mel Wilson" <mwilson@the-wire.com> wrote in message news:Ex02/ks/KzJT089yn@the-wire.com...[color=blue]
      > In article <mailman.112.10 71251837.9307.p ython-list@python.org >,
      > "=?iso-8859-1?B?UmVuZek=?=" <rlogan@hmc.edu > wrote:[color=green]
      > >I wanted to know the order of implicit conversions and which sort of =
      > >values
      > >allow them. From searching around in books and the archive of this =
      > >mailing
      > >list, it seems to be that only numbers are implicitly converted within =
      > >each
      > >other and bools can be implicitly converted to ints? However, I'm unable =
      > >to
      > >find any other implicit conversions and the order of the implicit
      > >conversions (something like int->float->long). Any help would be greatly
      > >apprectiated . Also, I'm not on the mailing list so can everyone please =
      > >cc me
      > >in the replies?[/color]
      >
      > Anybody?
      >
      > Speaking as a Python programmer (not a Python developer),
      > I would say that Python doesn't generally do implicit
      > conversions.[/color]
      To be more specific Python Virtual Machine doesn't do implicit
      conversions. However any class including builtin ones can
      convert any input argument to any other type. From the
      outer point of view (e.g. user of int class) it's implicit conversion,
      but from inner point of view (e.g. int class) there is no implicit
      conversions of input arguments so the int class has to explicitly
      convert them.

      -- Serge.


      Comment

      • John Roth

        #4
        Re: Implicit Conversions

        The coercion rules are documented in the Python Reference Manual under
        Data Model - Special Method Names - Coercion Rules.

        John Roth


        "Reneé" <rlogan@hmc.edu > wrote in message
        news:mailman.11 2.1071251837.93 07.python-list@python.org ...
        I wanted to know the order of implicit conversions and which sort of values
        allow them. From searching around in books and the archive of this mailing
        list, it seems to be that only numbers are implicitly converted within each
        other and bools can be implicitly converted to ints? However, I'm unable to
        find any other implicit conversions and the order of the implicit
        conversions (something like int->float->long). Any help would be greatly
        apprectiated. Also, I'm not on the mailing list so can everyone please cc me
        in the replies?
        Reneé




        Comment

        Working...