python 数字相关

工厂:

int(),          long(),           float()

 

绝对值: abs()

abs(3)  #=> 3            

abs(-3)  #=> 3

 

浮点型四舍五入: round()

round(3)  #=> 3.0

round(3.45)  #=> 3.0

round(-3.49)  #=> -3.0

round(-3.49,1)  #=> -3.5

 

八进制: oct()

oct(255)  #=> '0377'

 

十六进制: hex()

hex(255)  #=> '0xff'

 

ASCII码转换: ord(chr)  chr(num)

ord('a')  #=> 97

chr(97)  #=> 'a'

 

Unicode码转换: unichr(num)

unichr(97)

 

随机: random

random.randint()

random.uniform()

random.random()

random.choice()

random.shuffle()

posted on 2011-03-14 22:20  真阿当  阅读(119)  评论(0编辑  收藏  举报