[Tutor] A Million Sevens

Alan Gauld alan.gauld at btinternet.com
Sat Nov 18 10:49:53 CET 2006


"Chris Hengge" <pyro9219 at gmail.com> wrote

> Not that it changes your reply, but just for my own sanity:
> int('7' * 10 ** 6) <- does this not just type-cast a char into an 
> int?

Chris, I suspect you may come from a C background?

Type *conversion* in Python is very differentb from
type *casting* in C.

type casting says take the binary data stored at x and treat
it as a different type, thats pretty well instantaneous.

typecasting (int)'77' in C will not give you the number
77(decimal) but will give you the hex value 0x3737
which is entirely different (actually 14135!).

Now typecasting in C++ is somewhat different, especially
if you use dynamic casts and that can involve converting
the type rather than just treating the existing data differently...
Because of this confusion over the word cast I prefer
to refer to Python as doing type conversions.

Type conversion says take the data entity in variable x
and change its internal structure to the representation
of a new type. Thats a much more complex operation.

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list