程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python module and function help document quick view method example

編輯:Python

Catalog

introduction

General help functions help()

Module help query

see .py Common modules at the end

View the built-in module

Query function information

Check all the functions under the module

Check the specific function information under the module

Another way to view function information

introduction

python One of the advantages is that there are a lot of built-in and online modules (module) resources , It can provide rich functions , When using these modules , If you go to the website every time to find online documents, it will be too time-consuming , The results are not necessarily accurate . So here is python The view help function comes with , You can quickly find out how to use the required modules and functions without interruption during programming

General help functions help()

stay python On the command line, type help(), You can see :

>>> help()Welcome to Python 3.5's help utility!If this is your first time using Python, you should definitely check outthe tutorial on the Internet at http://docs.python.org/3.5/tutorial/.Enter the name of any module, keyword, or topic to get help on writingPython programs and using Python modules. To quit this help utility andreturn 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 comeswith a one-line summary of what it does; to list the modules whose nameor summary contain a given string such as "spam", type "modules spam".help>

Get into help Help document interface , According to the screen prompts, you can continue to type the corresponding keywords for query , Continue typing modules You can list all currently installed modules :

help> modulesPlease wait a moment while I gather a list of all available modules...AutoComplete _pyio filecmp pyscreezeAutoCompleteWindow _random fileinput pytweening...... Enter any module name to get more help. Or, type "modules spam" to searchfor modules whose name or summary contain the string "spam".

You can continue to type the corresponding module name to get the help information of the module .

This is a python General query help for , You can find almost all the help documents , But many times we don't need to query down hierarchically , Next, we will introduce how to directly query the help information of specific modules and functions .

Module help query see .py Common modules at the end

help(module_name)

For example, to query math How to use the module , You can do the following :

>>> import math>>> help(math)Help on built-in module math:NAME mathDESCRIPTION This module is always available. It provides access to the mathematical functions defined by the C standard.FUNCTIONS acos(...) acos(x) Return the arc cosine (measured in radians) of x....>>>

Use help(module_name) First of all import The module , In some tutorials, quotation marks are added to the module name instead of importing help('module_name'), This approach can cause problems , You can use math Module test , It is recommended to use import before use help() Function query

View the built-in module

sys.bultin_modulenames

>>> import sys>>> sys.builtin_module_names('_ast', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', ... 'zlib')>>>

Import required sys modular . The use listed here is generally self-contained C/C++ Compile linked modules

Query function information Check all the functions under the module

dir(module_name)

If we need to list math All function names under the module

>>> dir(math)['__doc__', '__loader__', '__name__',...]>>>

You also need to import the module first

Check the specific function information under the module

help(module_name.func_name)

If you look at math Under the sin() function

>>> help(math.sin)Help on built-in function sin in module math:sin(...) sin(x) Return the sine of x (measured in radians).>>> Another way to view function information

print(func_name.__doc__)

For example, check the built-in functions print usage

>>> print(print.__doc__)print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)Prints the values to a stream, or to sys.stdout by default....>>>

__doc__ There are two short underscores before and after , stay python Will merge into long underscores

python Medium help() similar unix Medium man Instructions , It will be very helpful to our programming if we are familiar with it

That's all python Modules and functions help the documentation to quickly view the details of the method example , More about viewing python For information about module function help documents, please pay attention to other relevant articles on the software development network !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved