python3有多少个内置模块(2023年最新分享)

导读:很多朋友问到关于python3有多少个内置模块的相关问题,本文首席CTO笔记就来为大家做个详细解答,供大家参考,希望对大家有所帮助!一起来看看吧!

python3 有多少内置函数

我刚刚数了下Python3.x一共有153个内置函数

具体如下:

['ArithmeticError', 'AssertionError', 'AttributeError', 'BaseException', 'BlockingIOError', 'BrokenPipeError', 'BufferError', 'BytesWarning', 'ChildProcessError', 'ConnectionAbortedError', 'ConnectionError', 'ConnectionRefusedError', 'ConnectionResetError', 'DeprecationWarning', 'EOFError', 'Ellipsis', 'EnvironmentError', 'Exception', 'False', 'FileExistsError', 'FileNotFoundError', 'FloatingPointError', 'FutureWarning', 'GeneratorExit', 'IOError', 'ImportError', 'ImportWarning', 'IndentationError', 'IndexError', 'InterruptedError', 'IsADirectoryError', 'KeyError', 'KeyboardInterrupt', 'LookupError', 'MemoryError', 'ModuleNotFoundError', 'NameError', 'None', 'NotADirectoryError', 'NotImplemented', 'NotImplementedError', 'OSError', 'OverflowError', 'PendingDeprecationWarning', 'PermissionError', 'ProcessLookupError', 'RecursionError', 'ReferenceError', 'ResourceWarning', 'RuntimeError', 'RuntimeWarning', 'StopAsyncIteration', 'StopIteration', 'SyntaxError', 'SyntaxWarning', 'SystemError', 'SystemExit', 'TabError', 'TimeoutError', 'True', 'TypeError', 'UnboundLocalError', 'UnicodeDecodeError', 'UnicodeEncodeError', 'UnicodeError', 'UnicodeTranslateError', 'UnicodeWarning', 'UserWarning', 'ValueError', 'Warning', 'WindowsError', 'ZeroDivisionError', '_', '__build_class__', '__debug__', '__doc__', '__import__', '__loader__', '__name__', '__package__', '__spec__', 'abs', 'all', 'any', 'ascii', 'bin', 'bool', 'bytearray', 'bytes', 'callable', 'chr', 'classmethod', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'format', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', 'len', 'license', 'list', 'locals', 'map', 'max', 'memoryview', 'min', 'next', 'object', 'oct', 'open', 'ord', 'pow', 'print', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', 'tuple', 'type', 'vars', 'zip']

python有哪些模块

Python是一门非常高级的编程语言,内置了许多标准模块,比如:sys、os、datetime等。

os模块

os.getcwd() # 获取当前工作目录,即当前python脚本工作的目录路径

os.chdir("dirname") # 改变当前脚本工作目录;相当于shell下cd

os.curdir # 返回当前目录: ('.')

os.pardir # 获取当前目录的父目录字符串名:('..')

os.makedirs('dirname1/dirname2') # 可生成多层递归目录

os.removedirs('dirname1') # 若目录为空,则删除,并递归到上一级目录,如若也为空,则删除,依此类推

os.mkdir('dirname') # 生成单级目录;相当于shell中mkdir dirname

os.rmdir('dirname') # # 删除单级空目录,若目录不为空则无法删除,报错;相当于shell中rmdir dirname

os.listdir('dirname') # 列出指定目录下的所有文件和子目录,包括隐藏文件,并以列表方式打印

os.remove() # 删除一个文件

os.rename("oldname","newname") # 重命名文件/目录

os.stat('path/filename') # 获取文件/目录信息

os.sep # 输出操作系统特定的路径分隔符,win下为"\\",Linux下为"/"

os.linesep # 输出当前平台使用的行终止符,win下为"\t\n",Linux下为"\n"

os.pathsep # 输出用于分割文件路径的字符串 win下为;,Linux下为:

os.name # 输出字符串指示当前使用平台。win-'nt'; Linux-'posix'

os.system("bash command") # 运行shell命令,直接显示

os.environ # 获取系统环境变量

os.path.abspath(path) # 返回path规范化的绝对路径

os.path.split(path) # 将path分割成目录和文件名二元组返回

os.path.dirname(path) # 返回path的目录。其实就是os.path.split(path)的第一个元素

os.path.basename(path) #

返回path最后的文件名。如何path以/或\结尾,那么就会返回空值。即os.path.split(path)的第二个元素

os.path.exists(path) # 如果path存在,返回True;如果path不存在,返回False

os.path.isabs(path) # 如果path是绝对路径,返回True

os.path.isfile(path) # 如果path是一个存在的文件,返回True。否则返回False

os.path.isdir(path) # 如果path是一个存在的目录,则返回True。否则返回False

os.path.join(path1[, path2[, ...]]) # 将多个路径组合后返回,第一个绝对路径之前的参数将被忽略

os.path.getatime(path) # 返回path所指向的文件或者目录的最后访问时间

os.path.getmtime(path) # 返回path所指向的文件或者目录的最后修改时间

os.path.getsize(path) # 返回path的大小

sys模块

sys.argv # 命令行参数List,第一个元素是程序本身路径

sys.exit(n) # 退出程序,正常退出时exit(0)

sys.version # 获取Python解释程序的版本信息

sys.maxint # 最大的Int值

sys.path # 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值

sys.platform # 返回操作系统平台名称

datetime模块

datetime.today()返回一个表示当前本期日期时间的datetime对象

datetime.now([tz])返回指定时区日期时间的datetime对象,如果不指定tz参数则结果同上

datetime.utcnow()返回当前utc日期时间的datetime对象

datetime.fromtimestamp(timestamp[, tz])根据指定的时间戳创建一个datetime对象

datetime.utcfromtimestamp(timestamp)根据指定的时间戳创建一个datetime对象

datetime.strptime(date_str, format)将时间字符串转换为datetime对象

Python必学的模块有哪些?

简单来说,模块就是一堆代码实现某个功能,它们是已经写好的.py文件,在我们的.py文件中只需要用import导入模块就能使用它的功能了。

Python中的模块有内置标准模块、开源模块和自定义模块。

内置标准模块就是Python自带的模块,即下载好Python就可以直接导入使用的模块,例如我们之前使用过的math模块、time模块等。

开源模块就是不收费的由好心人写好的模块,我们可以通过下载这些模块后导入使用,开源模块一般也被我们称为第三方模块,例如数据处理工具NumPy、Pandas,以及深度学习著名框架Tensorflow都属于开源模块。

自定义模块与开源模块相对应,开源模块是他人写的,而自定义模块就是自己写好的模块。

Python常见的三个模块

一、time与datetime模块

在Python中,通常有这几种方式来表示时间:

时间戳(timestamp):通常来说,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量。我们运行“type(time.time())”,返回的是float类型。

格式化的时间字符串(Format String)

结构化的时间(struct_time):struct_time元组共有9个元素共九个元素:(年,月,日,时,分,秒,一年中第几周,一年中第几天,夏令时)

二、random模块

三、os模块

os模块是与操作系统交互的一个接口

python3有多少个内置模块(2023年最新分享)  第1张

结语:以上就是首席CTO笔记为大家整理的关于python3有多少个内置模块的相关内容解答汇总了,希望对您有所帮助!如果解决了您的问题欢迎分享给更多关注此问题的朋友喔~

以上内容为新媒号(sinv.com.cn)为大家提供!新媒号,坚持更新大家所需的互联网后端知识。希望您喜欢!

版权申明:新媒号所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流,不声明或保证其内容的正确性,如发现本站有涉嫌抄袭侵权/违法违规的内容。请发送邮件至 k2#88.com(替换@) 举报,一经查实,本站将立刻删除。

(0)
上一篇 2023-09-23
下一篇 2023-09-23

相关推荐

发表回复

登录后才能评论