Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Python

Thuộc tính class built-in __doc__ trong Python

Mọi function có built-in attribute __doc__ trả về docstring định nghĩa trong source code.

Ví dụ

def foo():
    \"\"\" This is an example of how a doc_string looks like.
        This string gives useful information about the function being defined.
    \"\"\"
    pass

print(foo.__doc__)

Kết quả

This is an example of how a doc_string looks like.
    This string gives useful information about the function being defined.

Class cũng có __doc__ (docstring đầu class).