【Python】查看模块及模块包含的方法

1、dir:查看模板中的方法

import itertools
print(dir(itertools))

结果

[’_doc_’, ‘_loader_’, ‘_name_’, ‘_package_’, ‘_spec_’,
‘_grouper’, ‘_tee’, ‘_tee_dataobject’, ‘accumulate’, ‘chain’,
‘combinations’, ‘combinations_with_replacement’, ‘compress’, ‘count’,
‘cycle’, ‘dropwhile’, ‘filterfalse’, ‘groupby’, ‘islice’,
‘permutations’, ‘product’, ‘repeat’, ‘starmap’, ‘takewhile’, ‘tee’,
‘zip_longest’]

2、help:查看模块或方法的内容

import itertools
print(help(itertools.product()))

结果
【Python】查看模块及模块包含的方法_第1张图片
另外一种方法:
cmd进入到python后,输入help()进入交互式,然后直接输入模块或是方法
【Python】查看模块及模块包含的方法_第2张图片
3、sys.builtin_module_names查看内置模块

import sys
print(sys.builtin_module_names)

结果:

(’_ast’, ‘_bisect’, ‘_blake2’, ‘_codecs’, ‘_codecs_cn’, ‘_codecs_hk’,
‘_codecs_iso2022’, ‘_codecs_jp’, ‘_codecs_kr’, ‘_codecs_tw’,
‘_collections’, ‘_csv’, ‘_datetime’, ‘_functools’, ‘_heapq’, ‘_imp’,
‘_io’, ‘_json’, ‘_locale’, ‘_lsprof’, ‘_md5’, ‘_multibytecodec’,
‘_opcode’, ‘_operator’, ‘_pickle’, ‘_random’, ‘_sha1’, ‘_sha256’,
‘_sha3’, ‘_sha512’, ‘_signal’, ‘_sre’, ‘_stat’, ‘_string’, ‘_struct’,
‘_symtable’, ‘_thread’, ‘_tracemalloc’, ‘_warnings’, ‘_weakref’,
‘_winapi’, ‘array’, ‘atexit’, ‘audioop’, ‘binascii’, ‘builtins’,
‘cmath’, ‘errno’, ‘faulthandler’, ‘gc’, ‘itertools’, ‘marshal’,
‘math’, ‘mmap’, ‘msvcrt’, ‘nt’, ‘parser’, ‘sys’, ‘time’, ‘winreg’,
‘xxsubtype’, ‘zipimport’, ‘zlib’)

4、模块是内置还是外置

【Python】查看模块及模块包含的方法_第3张图片

你可能感兴趣的:(Python3)