当前位置:首页 > Python教程 > python技巧

Python基础教程—2019/1/29

2019/1/29

// 整除
** 乘方
0x 十六进制 0b 二进制 0o八进制

常用模块和函数
1:pow() 乘方

>> pow(2,3)
8
>> 2**3
8
>>

2:abs() 绝对值

3:round() 向最接近的那个数取整,如果一样,向偶数取整

>> round(2/3)
1
>>
4:math库的floor()函数,向下取整
>> import math
>> math.floor(32.9)
32
>>

5:math库的ceil()向上取整

>> math.ceil(32.9)
33
>> math.ceil(33)
33
>>

6:sqrt()开平方根

>> math.sqrt(9)
3.0
>>
导入方式2:
>> from math import ceil
>> ceil(32.4)
33
>>
处理虚数的模块 cmath
>> import cmath
>> cmath.sqrt(-9)
3j
>>

原文:http://blog.51cto.com/12884584/2347747


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐