Python内置函数help()

这篇博客介绍了Python3.7的内置帮助系统,包括如何使用`help()`函数获取模块、关键字、符号等的帮助信息。通过示例展示了如何查询`if`语句、`input()`函数、`os`模块等,以及如何搜索和浏览所有可用模块和关键词。此外,还提到了在使用`os`模块时遇到的问题和解决方法。
摘要由CSDN通过智能技术生成

help([object])
在这里插入图片描述
代码实验:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> help()

Welcome to Python 3.7's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> if
The "if" statement
******************

The "if" statement is used for conditional execution:

   if_stmt ::= "if" expression ":" suite
               ("elif" expression ":" suite)*
               ["else" ":" suite]

It selects exactly one of the suites by evaluating the expressions one
by one until one is found to be true (see section Boolean operations
for the definition of true and false); then that suite is executed
(and no other part of the "if" statement is executed or evaluated).
If all expressions are false, the suite of the "else" clause, if
present, is executed.

Related help topics: TRUTHVALUE

help> quit

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
>>> 
>>> help()

Welcome to Python 3.7's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> 

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
>>> 
>>> 
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> help(input)
Help on built-in function input in module builtins:

input(prompt=None, /)
    Read a string from standard input.  The trailing newline is stripped.
    
    The prompt string, if given, is printed to standard output without a
    trailing newline before reading input.
    
    If the user hits EOF (*nix: Ctrl-D, Windows: Ctrl-Z+Return), raise EOFError.
    On *nix systems, readline is used if available.

>>> help(os)
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    help(os)
NameError: name 'os' is not defined
>>> help("os")

>>> 
>>> help(str)

>>> 
>>> help("modules")

Please wait a moment while I gather a list of all available modules...


Warning (from warnings module):
  File "D:\Python37\lib\pkgutil.py", line 92
    __import__(info.name)
MatplotlibDeprecationWarning: 
The matplotlib.compat module was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
PIL                 autocomplete        idle_test           search
__future__          autocomplete_w      idlelib             searchbase
__main__            autoexpand          imaplib             searchengine
_abc                base64              imghdr              secrets
_ast                bdb                 imp                 select
_asyncio            binascii            importlib           selectors
_bisect             binhex              inspect             selenium
_blake2             bisect              io                  setuptools
_bootlocale         browser             iomenu              shelve
_bz2                builtins            ipaddress           shlex
_codecs             bz2                 itertools           shutil
_codecs_cn          cProfile            json                signal
_codecs_hk          calendar            keyword             site
_codecs_iso2022     calltip             kiwisolver          six
_codecs_jp          calltip_w           lib2to3             smtpd
_codecs_kr          cgi                 linecache           smtplib
_codecs_tw          cgitb               locale              sndhdr
_collections        chunk               logging             socket
_collections_abc    cmath               lzma                socketserver
_compat_pickle      cmd                 macosx              sqlite3
_compression        code                macpath             squeezer
_contextvars        codecontext         mailbox             sre_compile
_csv                codecs              mailcap             sre_constants
_ctypes             codeop              mainmenu            sre_parse
_ctypes_test        collections         marshal             ssl
_datetime           colorizer           math                stackviewer
_decimal            colorsys            matplotlib          stat
_dummy_thread       compileall          mimetypes           statistics
_elementtree        concurrent          mmap                statusbar
_functools          config              modulefinder        string
_hashlib            config_key          msilib              stringprep
_heapq              configdialog        msvcrt              struct
_imp                configparser        multicall           subprocess
_io                 contextlib          multiprocessing     sunau
_json               contextvars         netrc               symbol
_locale             copy                nntplib             symtable
_lsprof             copyreg             nt                  sys
_lzma               crypt               ntpath              sysconfig
_markupbase         csv                 nturl2path          tabnanny
_md5                ctypes              numbers             tarfile
_msi                curses              numpy               telnetlib
_multibytecodec     cycler              opcode              tempfile
_multiprocessing    dataclasses         operator            test
_opcode             datetime            optparse            textview
_operator           dateutil            os                  textwrap
_osx_support        dbm                 outwin              this
_overlapped         debugger            paragraph           threading
_pickle             debugger_r          parenmatch          time
_py_abc             debugobj            parser              timeit
_pydecimal          debugobj_r          pathbrowser         tkinter
_pyio               decimal             pathlib             token
_queue              delegator           pdb                 tokenize
_random             difflib             percolator          tooltip
_sha1               dis                 pickle              trace
_sha256             distutils           pickletools         traceback
_sha3               doctest             pip                 tracemalloc
_sha512             dummy_threading     pipes               tree
_signal             dynoption           pkg_resources       tty
_sitebuiltins       easy_install        pkgutil             turtle
_socket             editor              platform            turtledemo
_sqlite3            email               plistlib            types
_sre                encodings           poplib              typing
_ssl                ensurepip           posixpath           undo
_stat               enum                pprint              unicodedata
_string             errno               profile             unittest
_strptime           faulthandler        pstats              urllib
_struct             filecmp             pty                 urllib3
_symtable           fileinput           py_compile          uu
_testbuffer         filelist            pyclbr              uuid
_testcapi           fnmatch             pydoc               venv
_testconsole        formatter           pydoc_data          warnings
_testimportmultiple fractions           pyexpat             wave
_testmultiphase     ftplib              pylab               weakref
_thread             functools           pyparse             webbrowser
_threading_local    gc                  pyparsing           window
_tkinter            genericpath         pyshell             winreg
_tracemalloc        getopt              query               winsound
_warnings           getpass             queue               wsgiref
_weakref            gettext             quopri              xdrlib
_weakrefset         glob                random              xml
_winapi             grep                re                  xmlrpc
abc                 gzip                redirector          xxsubtype
aifc                hashlib             replace             you_get
antigravity         heapq               reprlib             zipapp
argparse            help                rlcompleter         zipfile
array               help_about          rpc                 zipimport
ast                 history             rstrip              zlib
asynchat            hmac                run                 zoomheight
asyncio             html                runpy               zzdummy
asyncore            http                runscript           
atexit              hyperparser         sched               
audioop             idle                scrolledlist        

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".

>>> 
>>> import matplotlib
>>> 
>>> help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not                 

>>> 
>>> help
Type help() for interactive help, or help(object) for help about object.
>>> keywords
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    keywords
NameError: name 'keywords' is not defined
>>> help()

Welcome to Python 3.7's help utility!

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at https://docs.python.org/3.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, symbols, or topics, type
"modules", "keywords", "symbols", or "topics".  Each module also comes
with a one-line summary of what it does; to list the modules whose name
or summary contain a given string such as "spam", type "modules spam".

help> keywords

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               class               from                or
None                continue            global              pass
True                def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
break               for                 not                 

help> 

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.
>>> 
>>> 
>>> 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值