4

So here is what I am typing

>>> list = [1,2,3]
>>> list.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"

The problem being that it literally prints "\n" instead of printing a new line, making more complicated doc strings almost impossible to read.

The same thing happens with all of the other built-in classes I have tried.

The version information I get from python when I open it is: Python 2.7.5 (default, Jul 16 2013, 14:23:29) [GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin

0

1 Answer 1

10

That is because the list.__doc__ is a string.

When you just type list.__doc__ you will get the contents like this :

>>> list.__doc__
"list() -> new empty list\nlist(iterable) -> new list initialized from iterable's items"

However if you type print list.__doc__

>>> print list.__doc__
list() -> new empty list
list(iterable) -> new list initialized from iterable's items

So the print function properly formats the string to include the linebreak.

Hope that helps :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.