Python基础入门—常用函数笔记

来源:互联网 发布:seo渠道 编辑:程序博客网 时间:2024/05/17 08:46

id():内建函数可以查看每个对象的内存地址,即身份。

id(1)

type():内建函数能够查看对象的类型。

type(123)

divmod(5,2) > (2,1):#表示5除以2,返回了商和余数

>>>divmod(5,2)(2,1)

round(1.2348,3) >1.235 实现四舍五入

>>>round(1.237,3)1.235

绝对值

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

乘方、开方、对数运算等等,要实现这些运算,需要用到python中的一个模块:Math

>>>dir(math)[ 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'copysign', 'cos', 'cosh', 'degrees', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'hypot', 'isinf', 'isnan', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'modf', 'pi', 'pow', 'radians', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'trunc']

dir(module)是一个非常有用的指令,可以通过它查看任何模块中所包含的工具。

>>>dir(module)[模块内容]

运算优先级
| :————- |:————-:|
| 算符 | 描述 |
|lambda | Lambda表达式 |
|or | 布尔“或”|
| and | 布尔“与”|
| not x | 布尔“非”|
| in,not in | 成员测试|
| is,is not | 同一性测试|
| <,<=,>,>=,!=,== | 比较|
| \ | 按位或|
| ^ | 按位异或|
| & | 按位与|
| <<,>> | 移位|
| +,- | 加法与减法|
| *,/,% | 乘法、除法与取余|
| +x,-x | 正负号|
| ~x | 按位翻转|
| ** | 指数|
| x.attribute | 属性参考|
| x[index] | 下标|
| x[index:index] | 寻址段|
| f(arguments…) | 函数调用|
| (experession,…) | 绑定或元组显示|
| [expression,…] | 列表显示|
| {key:datum,…} | 字典显示|
| ‘expression,…’ | 字符串转换|

0 0
原创粉丝点击