Python内置函数一览表

为了提高程序员的开发效率,Python 提供了很多可以直接拿来用的函数(初学者可以先理解为方法),每个函数都可以帮助程序员实现某些具体的功能。

举个例子,在 Python 2.x 中 print 只是一个关键字,但在 Python 3.x 中,print 是用于打印输出的函数,而且还是一个内置函数,通过此函数,我们可以直接将数据做输出操作,比如说:

复制代码
>>>print("csdn")
csdn

除了 print() 函数之外,Python 还提供了很多内置函数,表 1 中罗列出了 Python 3.x 环境中的所有内置函数。

内置函数
abs() delattr() hash() memoryview() set()
all() dict() help() min() setattr()
any() dir() hex() next() slicea()
ascii() divmod() id() object() sorted()
bin() enumerate() input() oct() staticmethod()
bool() eval() int() open() str()
breakpoint() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() import()
complex() hasattr() max() round()
[表 1 Python 3.x内置函数]

需要注意的是,开发者不建议使用以上内置函数的名字作为标识符使用(作为某个变量、函数、类、模板或其他对象的名称),虽然这样做 Python 解释器不会报错,但这会导致同名的内置函数被覆盖,从而无法使用。例如:

复制代码
>>> print="csdn"   #Python解释器不会报错
>>> print(print)
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    print(print)
TypeError: 'str' object is not callable
相关推荐
是店小二呀6 分钟前
鸿蒙PC开源移植:CodeLite原生IDE与Remote Agent适配
android·智能手机·远程桌面
Brilliantwxx20 分钟前
【STM32】 SPI阻塞式通信与HAL源码(串口读ID实战)
开发语言·stm32·单片机·嵌入式硬件·ecmascript
打工仔折腾 AI26 分钟前
Pascal Editor 本地部署实战:Bun 启动 WebGPU 3D 编辑器并解决公网访问报错
人工智能·后端·python·性能优化
m0_5474866626 分钟前
《Python从入门到数据分析应用》全套PPT课件2026
python·数据分析
All for pursuit.28 分钟前
FastAPI+Ollama 部署本地AI大模型对话助手
python·github·aigc·ollama
吠品32 分钟前
Nginx负载均衡配置与线上故障排查的一些经验
java·开发语言·数据库
边境悍匪38 分钟前
蜗牛学苑 Java 智能体学习 Day44|Vue 前端项目搭建 思维导图复盘
java·开发语言·spring boot·学习·阿里云
Python图像识别40 分钟前
10-【2027毕设】YOLO11PCB缺陷检测识别系统 - Python完整源码+PyQt5界面+训练模型+数据集
python·深度学习·yolo·毕业设计·毕设
szephyr43 分钟前
用 Python 写自动化脚本:定时任务、文件批处理、自动出报表
python·自动化·pandas·脚本·定时任务
终端安全笔记44 分钟前
iOS 27 给了租赁一个新工具,但它只认受监督的设备
android·网络·安全·ios