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
相关推荐
哈里谢顿19 分钟前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
alexhilton10 小时前
使用FunctionGemma进行设备端函数调用
android·kotlin·android jetpack
冬奇Lab13 小时前
InputManagerService:输入事件分发与ANR机制
android·源码阅读
用户83562907805115 小时前
无需 Office:Python 批量转换 PPT 为图片
后端·python
张小潇16 小时前
AOSP15 Input专题InputManager源码分析
android·操作系统
markfeng816 小时前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi17 小时前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee17 小时前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay17 小时前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤18 小时前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi