Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

Built-in Class Attribute __doc__ ใน Python ทำอะไร

ทุกฟังก์ชันมี Built-in Attribute __doc__ คืน Docstring ที่นิยามใน Source Code ของฟังก์ชัน

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__)

ผลลัพธ์:

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