Typecasting

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Mon Feb 23 09:05:54 EST 2004


Duncan Booth wrote:

> "Shah, Rajesh \(GE Consumer & Industrial\)" <Rajesh.Shah at ge.com> wrote in 
> news:mailman.198.1077534828.27104.python-list at python.org:
> 
> 
>>Hi Everybody,
>>
>>Can you guide me to convert string into Int datatype?
>>(i.e. How can we convert string into int? like '555' into 555)
>>
>>Thanks in advance.
>>
>>~Rajesh
>>
>>
> 
> 
>>>>int('555')
> 
> 555
> 
> In general, if there is a conversion defined between two types then you do 
> the conversion by calling the destination type. So calling int() will 
> convert a string, float, or long to an int (but it won't convert a complex 
> number); calling str() will convert just about anything to a string; 
> calling list will convert other sequences into a list and so on.

THe important word here is 'convert'. Python doesn't know about the
concept of type 'casting'... ;-)

--Irmen



More information about the Python-list mailing list