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
相关推荐
陶陶name几秒前
Metal Compute Pipeline:Metal-C++ 环境配置与简单算子实现
开发语言·c++
认真敲代码的小火龙1 分钟前
【JAVA项目】基于JAVA的宿舍管理系统
java·开发语言·课程设计
无限进步_1 分钟前
寻找数组中缺失数字:多种算法详解与比较
c语言·开发语言·数据结构·算法·排序算法·visual studio
lsx2024063 分钟前
C 标准库 - <assert.h>
开发语言
Wzx1980125 分钟前
go接受输入方式
开发语言·后端·golang
黑马源码库miui520865 分钟前
JAVA成人用品商城系统源码微信小程序+h5+安卓+ios
android·java·微信小程序
多恩Stone6 分钟前
【3DV 进阶-9】Hunyuan3D2.1 中的 MoE
人工智能·pytorch·python·算法·aigc
CC.GG8 分钟前
【Qt】Qt背景与环境搭建
开发语言·qt
爱打代码的小林8 分钟前
网络爬虫基础
爬虫·python
B站计算机毕业设计之家9 分钟前
大数据项目:基于python电商平台用户行为数据分析可视化系统 电商订单数据分析 Django框架 Echarts可视化 大数据技术(建议收藏)
大数据·python·机器学习·数据分析·django·电商·用户分析