type convert in python

there is no type cast in python, every conversion in python will create a new object. Not like in Java and C++, the original object will still be exist in the system.

there are some of the built in functions in python to help the conversion. Such as:

>>> int('123')
123
>>> int(45.67)
45
>>> round(1.15, 1)
1.2
>>> float(10)
10.0
>>> divmod(15, 6)
(2, 3)
>>> ord('a')
97
>>> chr(65)
'A'

    round(number[, ndigits]) -> number
    
    Round a number to a given precision in decimal digits (default 0 digits).
    This returns an int when called with one argument, otherwise the
    same type as the number. ndigits may be negative.


 

posted on 2012-08-29 21:12  很遗憾我不是  阅读(322)  评论(0编辑  收藏  举报