O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Type Conversion

Sometimes it’s necessary to perform conversions between the built-in types. To convert between types you simply use the type name as a function. In addition, several built-in functions are supplied to perform special kinds of conversions. All of these functions return a new object representing the converted value.

FunctionDescription
int(x [,base])Converts x to an integer. base specifies the base if x is a string.
long(x [,base] )Converts x to a long integer. base specifies the base if x is a string.
float(x)Converts x to a floating-point number.
complex(real [,imag])Creates a complex number.
str(x)Converts object x to a string representation.
repr(x)Converts object x to an expression string.
eval(str)Evaluates a string and returns an ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required