Wiederholung: Dokumentations-Strings

In Chapter 11 wurden Docstrings im Detail behandelt. Diese String-Literale erscheinen am Anfang verschiedener Code-Strukturen und werden von Python automatisch in _ _doc_ _-Attributen von Objekten gespeichert. Das funktioniert bei Moduldateien, Funktionen sowie Klassen und Methoden. Die folgende Datei docstr.py ist ein kurzes, aber vollständiges Beispiel, in dem alle Orte vorkommen, an denen Docstrings in Ihrem Code stehen dürfen. Alle dürfen auch Blockstrings in dreifachen Anführungszeichen sein:

"Ich bin: docstr._ _doc_ _" class spam: "Ich bin: spam._ _doc_ _ or docstr.spam._ _doc_ _" def method(self, arg): "Ich bin: spam.method._ _doc_ _ or self.method._ _doc_ _" pass def func(args): "Ich bin: docstr.func._ ...

Get Einfüehrung in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.