内置函数一

1.abs(5)#返回绝对值

2.all()#所有为真返回true,为假返回false

3.any()#其中一个为真就返回true

4.bin()#返回二进制形式

5.bool()#为真返回 true,为假返回false

6.callable()#若为可执行返回 true,反之返回false

7.chr()#将数字转换为字母

8. ord()#将assic字符转化为数字

9.divmod()#取整除及余数

10.enumerate()#改变起始数据序列

for i, season in enumerate(['Spring', 'Summer', 'Fall', 'Winter'],start=1):
print i, season
1 Spring
2 Summer
3 Fall
4 Winter
11.dir()#查看对像内所有属于及方法

12.compile(source, filename, mode[, flags[, dont_inherit]])

中文说明:将source编译为代码或者AST对象。代码对象能够通过exec语句来执行或者eval()进行求值。

参数source:字符串或者AST(Abstract Syntax Trees)对象。

参数 filename:代码文件名称,如果不是从文件读取代码则传递一些可辨认的值。

参数model:指定编译代码的种类。可以指定为 ‘exec’,’eval’,’single’。

13.eval()#将字符串当成有效Python表达式来求值,并返回计算结果

eg:

x = 1
res=eval('x+1')
print (res)
 
原文地址:https://www.cnblogs.com/guisheng/p/6063900.html