Wednesday, February 11, 2009

Python Type Conversions

int(x [,base])converts x
to an integer
long(x [,base])converts x
to a long integer
float(x)converts x
to a floating-point number
complex(real [,imag])creates a complex number
str(x)converts x
to a string representation
repr(x)converts x
to an expression string
eval(str)evaluates str and returns an object
tuple(s)converts a sequence object to a tuple
list(s)converts a sequence object to a list
chr(x)converts an integer to a character
unichr(x)converts an integer to a Unicode character
ord(c)converts a character to its integer value
hex(x)converts an integer to a hexadecimal string
oct(x)converts an integer to an octal string

totalRings = int(userInput)
//where totalRings and userInput are variables

No comments: