473,387 Members | 1,789 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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é
Jul 18 '05 #1
3 2603
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Russell Reagan | last post by:
In a newer version of a chess program I am writing, I have created classes that are (more or less) drop in replacements for things that used to be plain old integer or enumerated variables (colors,...
9
by: Simon | last post by:
Hi All, Is it possible to disallow implicit casting for an operand of a function written in C? i.e. void foo(int a) {..} short b; foo(b) // error without explicit cast
15
by: buda | last post by:
Let me see if I got this :) 1. I know the rules for type conversions in arithmetic expressions 2. I know that an implicit type conversion is done at assignment, so float x = 1.23; int t = (int)...
11
by: Steve Gough | last post by:
Could anyone please help me to understand what is happening here? The commented line produces an error, which is what I expected given that there is no conversion defined from type double to type...
9
by: Girish | last post by:
Im trying to understand implicit type conversions from object -> string and vice versa. I have two classes, one Driver and one called StringWrapper. These are just test classes that try and...
11
by: Aaron Queenan | last post by:
Given the classes: class Class { public static implicit operator int(Class c) { return 0; } } class Holder
36
by: Chad Z. Hower aka Kudzu | last post by:
I have an implicit conversion set up in an assembly from a Stream to something else. In C#, it works. In VB it does not. Does VB support implicit conversions? And if so any idea why it would work...
17
by: arindam.mukerjee | last post by:
I was running code like: #include <stdio.h> int main() { printf("%f\n", 9/5); return 0; }
82
by: robert bristow-johnson | last post by:
here is a post i put out (using Google Groups) that got dropped by google: i am using gcc as so: $ gcc -v Using built-in specs. Target: i386-redhat-linux Configured with: ../configure...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.