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
相关推荐
神仙别闹3 分钟前
基于Python+Neo4j实现新冠信息挖掘系统
开发语言·python·neo4j
navyDagger4 分钟前
GAN生成对抗网络数学原理解释并实现MNIST数据集生产(附代码演示)
人工智能·python
没有梦想的咸鱼185-1037-16638 分钟前
【降尺度】ChatGPT+DeepSeek+python+CMIP6数据分析与可视化、降尺度技术与气候变化的区域影响、极端气候分析
python·chatgpt·数据分析
berryyan11 分钟前
傻瓜教程安装Trae IDE用AI撰写第一个AKShare接口脚本
python·trae
一杯凉白开11 分钟前
为了方便测试,程序每次崩溃的时候,我都让他跳转新页面,把日志显示出来
android
灏瀚星空28 分钟前
从基础到实战的量化交易全流程学习:1.3 数学与统计学基础——概率与统计基础 | 基础概念
笔记·python·学习·金融·概率论
Hellohistory33 分钟前
HOTP 算法与实现解析
后端·python
猫猫头有亿点炸33 分钟前
C语言大写转小写2.0
c语言·开发语言
伊织code35 分钟前
cached-property - 类属性缓存装饰器
python·缓存·cache·装饰器·ttl·property·cached-property
A达峰绮43 分钟前
设计一个新能源汽车控制系统开发框架,并提供一个符合ISO 26262标准的模块化设计方案。
大数据·开发语言·经验分享·新能源汽车