Python学习笔记 - 内建模块builtins

本文介绍了Python 3.7.4中的内建模块builtins,包括它与__builtins__的关系,以及通过help和dir命令查看其内容。模块包含64个异常类、26个非异常类和43个函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

版本:Python 3.7.4

Python自动加载的模块有如下7个:

C:\Users\Administrator>python
Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__']
>>>

导入builtins模块后,其实自动加载的__builtins__模块和手动导入的builtins模块是同一个模块。

>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'builtins']
>>>

使用help命令可以看到相同的输出内容,help(__builtins__) 和 help(builtins)。

内容主要有下面6各部分,分别是NAME,DESCRIPTION,CLASSES,FUNCTIONS,DATA,FILE

1.NAME
builtins - Built-in functions, exceptions, and other objects.
	
2.DESCRIPTION
Noteworthy: None is the `nil' object; Ellipsis represents `...' in slices.

3.CLASSES (共计90个类)
3.1类继承树
object
  |-BaseException
  |   |-Exception
  |   |   |-ArithmeticError
  |   |   |   |-FloatingPointError
  |   |   |   |-OverflowError
  |   |   |    \ZeroDivisionError
  |   |   |-AssertionError
  |   |   |-AttributeError
  |   |   |-BufferError
  |   |   |-EOFError
  |   |   |-ImportError
  |   |   |    \ModuleNotFoundError
  |   |   |-LookupError
  |   |   |   |-IndexError
  |   |   |    \KeyError
  |   |   |-MemoryError
  |   |   |-NameError
  |   |   |    \UnboundLocalError
  |   |   |-OSError
  |   |   |   |-BlockingIOError
  |   |   |   |-ChildProcessError
  |   |   |   |-ConnectionError
  |   |   |   |   |-BrokenPipeError
  |   |   |   |   |-ConnectionAbortedError
  |   |   |   |   |-ConnectionRefusedError
  |   |   |   |    \ConnectionResetError
  |   |   |   |-FileExistsError
  |   |   |   |-FileNotFoundError
  |   |   |   |-InterruptedError
  |   |   |   |-IsADirectoryError
  |   |   |   |-NotADirectoryError
  |   |   |   |-PermissionError
  |   |   |   |-ProcessLookupError
  |   |   |    \TimeoutError
  |   |   |-ReferenceError
  |   |   |-RuntimeError
  |   |   |   |-NotImplementedError
  |   |   |    \RecursionError
  |   |   |-StopAsyncIteration
  |   |   |-StopIteration
  |   |   |-SyntaxError
  |   |   |    \IndentationError
  |   |   |        \TabError
  |   |   |-SystemError
  |   |   |-TypeError
  |   |   |-ValueError
  |   |   |   |-UnicodeError
  |   |   |       |-UnicodeDecodeError
  |   |   |       |-UnicodeEncodeError
  |   |   |        \UnicodeTranslateError
  |   |   |-Warning
  |   |   |   |-BytesWarning
  |   |   |   |-DeprecationWarning
  |   |   |   |-FutureWarning
  |   |   |   |-ImportWarning
  |   |   |   |-PendingDeprecationWarning
  |   |   |   |-ResourceWarning
  |   |   |   |-RuntimeWarning
  |   |   |   |-SyntaxWarning
  |   |   |   |-UnicodeWarni
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值