写在前面:
Python内置模块就是标准库(模块)吗?或者说Python的自带string模块是内置模块吗?
答案是:
string不是内置模块,但它是标准库。也就是说Python内置模块和标准库并不是同一种东西。
什么是内置模块?在Python官方的文档这里有说到:
Python’s standard library is very extensive, offering a wide range of facilities as indicated by the long table of contents listed below. The library contains built-in modules (written in C) that provide access to system functionality such as file I/O that would otherwise be inaccessible to Python programmers, as well as modules written in Python that provide standardized solutions for many problems that occur in everyday programming.
它说明到内置模块是用C写的,提供了对系统功能的访问。从Python的标准库路径下面是找不到 sys 这个库的,原因就是它是操作系统相关,用C语言编写的。可以看到 string.py 模块,它是用Python写的。
虽然前面说明了内置模块不是标准库,但是内置模块可以划分到标准库一类中去,这里需要注意的是划分归类,而不是本质相同。这里说明内置模块不是标准库似乎有点吹毛求疵的意思,好像区不区分它们没有什么意义?是的&#