Skip to main content
Documents
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Built-in Functions (内置函数)

官方文档:https://docs.python.org/zh-cn/3.12/library/functions.html

获取内置函数:

import builtins
dir(builtins)

下面是 对所有内置函数按“功能用途”分类,并在每类中做了清晰排序(最常用 ➜ 次常用 ➜ 较少用)。

📌 一、数值与数学运算

(用于数值转换、格式化、数学操作)

排序依据:使用频率 + 常见程度

函数 用途
abs 返回绝对值
round 四舍五入
divmod 商与余数
pow 乘方(等价于 **)
max 最大值
min 最小值
sum 求和
hex 十六进制字符串
oct 八进制字符串
bin 二进制字符串
float 转换为浮点数
int 转换为整数
complex 复数

📌 二、序列 / 可迭代对象 处理

(遍历、组合、过滤、排序、生成序列)

① 构造与转换 ✅

函数 用途
list 列表
tuple 元组
set 集合
frozenset 不可变集合
dict 字典
str 字符串

② 迭代与遍历

函数 用途
iter 创建迭代器
aiter 异步迭代器
next 获取下一个元素
anext 异步 next
enumerate 枚举(带索引迭代)
zip 聚合多个可迭代
reversed 倒序迭代

③ 过滤 / 映射 / 排序 ✅

函数 用途
map 映射
filter 过滤
sorted 排序
range 数字序列

📌 三、逻辑判断与类型检查

(类型判断、属性判断、可调用检查)

函数 用途
isinstance 判断对象是否是某类
issubclass 判断是否子类
hasattr 判断对象是否有属性
getattr 获取属性
setattr 设置属性
delattr 删除属性
callable 判断对象是否可调用
bool 转换为布尔值

📌 四、对象与类相关

(面向对象工具)

函数 用途
object 所有类的基类
type 获取类型 / 生成类
property 属性装饰器
classmethod 类方法
staticmethod 静态方法
super 调用父类方法

📌 五、字符串与字符处理

函数 用途
chr 数字转字符
ord 字符转数字
ascii 转 ASCII 表示
repr 获取对象可打印字符串

📌 六、输入输出 I/O

函数 用途
print 打印输出
input 输入
open 打开文件

📌 七、调试与交互(控制台相关)

函数 用途
help 查看帮助
dir 查看对象成员
globals 查看全局变量
locals 查看局部变量
breakpoint 进入调试器
id 对象唯一标识
vars 对象 __dict__
copyright 显示版权
credits 致谢信息
license 许可信息
exit/quit 退出解释器

📌 八、编译与执行(动态代码)

函数 用途
eval 计算字符串表达式
exec 执行 Python 代码
compile 将字符串编译成代码对象

📌 九、内存与底层结构

函数 用途
bytes 不可变字节序列
bytearray 可变字节序列
memoryview 内存视图对象
hash 哈希值

📌 十、其它杂项

函数 用途
format 字符串格式化(底层)

📚 全部内置函数分类清单(适合复制收藏)

数学与数值运算:

    abs, round, divmod, pow, max, min, sum, hex, oct, bin, float, int, complex

序列与迭代:

    list, tuple, set, frozenset, dict, str,
    iter, aiter, next, anext, enumerate, zip, reversed,
    map, filter, sorted, range

逻辑与类型检查:

    isinstance, issubclass, hasattr, getattr, setattr, delattr, callable, bool

对象与类:

    object, type, property, classmethod, staticmethod, super

字符与字符串:

    chr, ord, ascii, repr

I/O 输入输出:

    print, input, open

调试与交互:

    help, dir, globals, locals, breakpoint, id, vars,
    copyright, credits, license,
    exit, quit

编译执行:

    eval, exec, compile

底层内存:

    bytes, bytearray, memoryview, hash

其他:

    format