By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

Implicit Conversions

P: n/a
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é
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <ma*************************************@python.or g>,
"=?iso-8859-1?B?UmVuZek=?=" <rl****@hmc.edu> wrote:
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?


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 "comprehensivity": 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.
Jul 18 '05 #2

P: n/a

"Mel Wilson" <mw*****@the-wire.com> wrote in message news:Ex02/ks/Kz*******@the-wire.com...
In article <ma*************************************@python.or g>,
"=?iso-8859-1?B?UmVuZek=?=" <rl****@hmc.edu> wrote:
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?


Anybody?

Speaking as a Python programmer (not a Python developer),
I would say that Python doesn't generally do implicit
conversions.

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.
Jul 18 '05 #3

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

John Roth
"Reneé" <rl****@hmc.edu> wrote in message
news:ma*************************************@pytho n.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é


Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.