Python 第一课

来源:互联网 发布:编程好看的字体 编辑:程序博客网 时间:2024/05/20 15:41

求绝对值

>>> abs(10)10>>> abs(-10)10

四舍五入

>>> round(1.234)1.0>>> round(1.234,2)1.23>>> #如果不清楚这个函数的用法,可以使用下面方法看帮助信息>>> help(round)

幂函数

>>> pow(2,3)        #2的3次方8

math模块(对于模块可能还有点陌生,不过不要紧,先按照下面代码实验一下,慢慢就理解了)

>>> import math         #引入math模块>>> math.floor(32.8)    #取整,不是四舍五入32.0>>> math.sqrt(4)        #开平方2.0
------------------------
>>> 2**38
-------------
>>> 10%31                           #求余数
---------------
>>> 10//33                          #求整数
-------------------------
>>> divmod(5,2)(2, 1)>>> divmod(9,2)(4, 1)
from :https://github.com/qiwsir/ITArticles/blob/master/BasicPython/103.md
0 0
原创粉丝点击