Python Basics (2): __doc__, document String docstring, Help ()

Source: Internet
Author: User

Os:windows 10 Chinese version, python:3.6.4

The document string (docstring) in Python appears in the first row of modules, functions, classes , and is used to describe these programs. It is ignored at execution time, but will

is stored in the __doc__ property of the module, function, and class by the compiler. However, not every module, function, class has a document string.

Part 1. Document strings for custom modules, functions, classes

New module dstest.py, stored in the Python installation directory (can be found when the import module);

Import Dstest, see the module dstest and its function Docfunc, class Docclass document string;

The Help () function is used to get the helper information for modules, functions, and classes that contain the respective document string information, and below to see how to use the

What information does the Help () function get-more information.

-Get Help for module Dstest--it contains the help information for the following function and class

-Get help information for a function

-Get information about a class

Part 2. Document string survey of built-in modules, functions, classes

Take module SYS as an example.

1. Direct access to __doc__ information

It's messy, can't see! Because it is the command line of the Windows platform? \ nto not be parsed into a carriage return!

2. Print __doc__ information using the print function

Parse the \ n as the carriage return character, more neat than the direct output __doc__.

3. Use the Help (SYS) function for assistance information

The best visual help information, should use this!

Take Django as an example to demonstrate a module with no docstring: author-ben.z

The content returned with __doc__ is empty (None), but help can be obtained by helping (Django).

Reference Links:

Python 3.6.5 documentation (there are all the Python files you need and you can choose the Python version)

3 ways to get help with Python

Python Basics (2): __doc__, document String docstring, Help ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.