[Tutor] List comprehension question
Alan Gauld
alan.gauld at btinternet.com
Mon Nov 8 02:03:36 CET 2010
"Hugo Arts" <hugo.yoshi at gmail.com> wrote
> Yes. A cast or typecast means converting some data to a different
> type, like converting floats to integers, strings to integers,
The term cast can be misleading however since in some
languages - those decended from C it means treating a piece
of data as if it were another type, which is different to converting
it.
For example in C:
char c = '7';
int x = (int)c; //this is type casting in C - it means treat c as
an integer
int y = atoi(c); // this is type conversion in C
x and y are not the same. x is effectively ord('7') whereas y is 7.
But in C only the first is referred to as a cast.
Not directly relevant in a Python thread but it can cause confusion
if newbies see references to casting in the C sense and think
it means type conversion.
Just feeling picky,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list