[Tutor] built in functions int(),long()

cino hilliard hillcino368@hotmail.com
Wed Jun 18 07:26:07 2003


Hi all,

The built in always avail functions

int( x[, radix])
Convert a string or number to a plain integer. If the argument is a string, 
it must contain a possibly signed decimal number representable as a Python 
integer, possibly embedded in whitespace; this behaves identical to 
string.atoi(x[, radix]). The radix parameter gives the base for the 
conversion and may be any integer in the range [2, 36], or zero. If radix is 
zero, the proper radix is guessed based on the contents of string; the 
interpretation is the same as for integer literals. If radix is specified 
and x is not a string, TypeError is raised. Otherwise, the argument may be a 
plain or long integer or a floating point number. Conversion of floating 
point numbers to integers truncates (towards zero). If the argument is 
outside the integer range a long object will be returned instead.


long( x[, radix])
Convert a string or number to a long integer. If the argument is a string, 
it must contain a possibly signed number of arbitrary size, possibly 
embedded in whitespace; this behaves identical to string.atol(x). The radix 
argument is interpreted in the same way as for int(), and may only be given 
when x is a string. Otherwise, the argument may be a plain or long integer 
or a floating point number, and a long integer with the same value is 
returned. Conversion of floating point numbers to integers truncates 
(towards zero).

These do not work properly or as defined.
examples
>>>long('123',2)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for long(): 123
>>>
>>>long('123')
123L                            OK
>>>
>>>long("123",10)
123L                           OK
>>>long('123',4)
27L                                      base 10  123 base 4 = 1323
same thing for int()
same thing for versions python 222, 23 a1


  3         3        3         3        3        6            2              
  (0^0)
2   +  13  +  33  +  43  =  49   =  7    =  343   = 117649

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE*.  
http://join.msn.com/?page=features/virus