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
相关推荐
许彰午2 小时前
100_Python面试常见问题汇总
java·python·面试
皓悦编程记2 小时前
【YOLO26 系列】基于YOLO26的垃圾分类检测系统【python源码+Pyqt5界面/WEB+数据集+训练代码】
python·qt·分类
滴滴滴嘟嘟嘟.3 小时前
强化学习消融实验-batch_size / clip_range / gae_lambda / lr
python·机器学习
2601_963932983 小时前
怀孕四个月能做流产吗?中期妊娠终止方式与子宫修护科普指南
python
zhr_math_king3 小时前
LangGraph-快速入门-第一个例子
python·langchain
爱吃苹果的梨叔3 小时前
2026年指挥中心分布式坐席怎么选?清虹创智让多系统、多坐席和大屏真正协同
python
没钥匙的锁14 小时前
16-Java反射机制:Spring IOC背后的核心技术
java·开发语言·spring
起予者汝也4 小时前
Python 数据结构
开发语言·数据结构·python
LadenKiller4 小时前
2026年量化工具增量,放回回测模拟实盘阶段判断
人工智能·python
石一峰6994 小时前
驱动:私有数据为什么要在三个地方各挂一遍?
数据库·python·算法