
docstring - print(__doc__) in Python 3 script - Stack Overflow
Tips on how to read the Python documentation?
You need to understand the difference between a reference and a tutorial. A tutorial teaches you how to do some new task, while a reference provides a whole bunch of information about all the fiddly little details of things. A reference is most useful to expert users who already know a subject well, but one thing that a novice can get out of reading a reference is that they can learn about the existence of a thing. As a novice, it is important to glance over the docs because that will give you a sense of the things that are possible using that module. You will discover what they don't know yet. You're not expected to instantly understand everything that is in there, but the docs will give you a place to start; a term or two that you can type into a search engine and research yourself. You start by looking at the reference to answer the question "is this thing possible?", then you find a tutorial to answer "how do I do this thing?", and then you return to the reference to answer really technical stuff like "how is it spelled?" or "what order do I have to use?".
More on reddit.comIs it a good idea to learn python from docs.python.org?
The Python documentation is bad, and you should feel bad.
Videos
Hey,
So I want to learn python for some of side projects. I am currently an advanced JavaScript programmer and so I was wondering if there was a python doc that is similar to javascript.info?
javascript.info is like the beginner most resource for learning js. Is there something else like that? A singular docs site that includes everything abt python (well not everything but you know what I mean :)
it seems
__doc__is useful to provide some documentation in, say, functions
This is true. In addition to functions, documentation can also be provided in modules. So, if you have a file named mymodule.py like this:
"""This is the module docstring."""
def f(x):
"""This is the function docstring."""
return 2 * x
You can access its docstrings like this:
>>> import mymodule
>>> mymodule.__doc__
'This is the module docstring.'
>>> mymodule.f.__doc__
'This is the function docstring.'
Now, back to your question: what does print(__doc__) do? Simply put: it prints the module docstring. If no docstring has been specified, __doc__ defaults to None.
Any function, class or module starting with a string literal has a non-empty __doc__; that initial string is taken as the documentation string; it'll be set to None if no such string is present. See the docstring term definition in the Python glossary.
When you download that Scikit script example, you'll see it starts with such a string:
"""
================================
Recognizing hand-written digits
================================
An example showing how the scikit-learn can be used to recognize images of
hand-written digits.
This example is commented in the
:ref:`tutorial section of the user manual <introduction>`.
"""
The print(__doc__) command simply re-uses that documentation string to write it to your terminal each time you run the script, and any other python tool (like the interactive interpreter help() function, for example) can introspect that same value.