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
相关推荐
岱宗夫up6 分钟前
基于OpenCode搭建Skills环境
python·低代码·ai编程
-To be number.wan7 分钟前
用 Pandas 分析自行车租赁数据:从时间序列到天气影响的完整实训
python·数据分析·pandas·数据可视化
##学无止境##29 分钟前
从0到1吃透Java负载均衡:原理与算法大揭秘
java·开发语言·负载均衡
Coding茶水间43 分钟前
基于深度学习的番茄叶子病虫害监测系统演示与介绍(YOLOv12/v11/v8/v5模型+Pyqt5界面+训练代码+数据集)
图像处理·人工智能·python·深度学习·yolo·目标检测
Desirediscipline1 小时前
#define _CRT_SECURE_NO_WARNINGS 1
开发语言·数据结构·c++·算法·c#·github·visual studio
知识即是力量ol1 小时前
多线程并发篇(八股)
java·开发语言·八股·多线程并发
尘缘浮梦1 小时前
协程asyncio入门案例 1
开发语言·python
没有bug.的程序员1 小时前
Lombok 深度进阶:编译期增强内核、@Data 与 @Builder 逻辑博弈及工业级避坑实战指南
java·开发语言·python·builder·lombok·data·编译器增强
guygg881 小时前
基于人工神经网络的彩色图像恢复 MATLAB实现
开发语言·计算机视觉·matlab
thorn_r1 小时前
RAG系统练手与思考
人工智能·python·机器学习·ai·自然语言处理