控制台中的Python换行符显示
因此,当我尝试打印Python函数的帮助/信息控制台中的Python换行符显示,python,Python,因此,当我尝试打印Python函数的帮助/信息函数时,\uuuu doc\uuuu,当文档字符串中出现\n时,控制台输出不是打印换行符,而是打印\n。有人能帮我解除这个功能吗 这是我的输出: 'divmod(x, y) -> (div, mod)\n\nReturn the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.' 我希望输出为: 'divmod(x, y) -> (div, mod) Return
函数时,\uuuu doc\uuuu
,当文档字符串中出现\n
时,控制台输出不是打印换行符,而是打印\n
。有人能帮我解除这个功能吗
这是我的输出:
'divmod(x, y) -> (div, mod)\n\nReturn the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.'
我希望输出为:
'divmod(x, y) -> (div, mod)
Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.'
附言:我已经在OSX、Ubuntu和Python2.7上试过了。看起来你是在交互式shell中检查了对象,而不是打印出来的。如果你是说打印,那就写下来
>>> "abc\n123"
"abc\n123"
>>> print "abc\n123"
abc
123
在Python3.x中,print是一个普通函数,因此必须使用()。以下(推荐)将在2.x和3.x中都适用:
>>> from __future__ import print_function
>>> print("abc\n123")
abc
123
您可能会发现使用(例如)
help(divmod)
而不是divmod.\uu\u doc\uu
更有用
In [6]: print divmod.__doc__
divmod(x, y) -> (div, mod)
Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.
但我建议你用
In [8]: help(divmod)
还是在伊皮顿
In [9]: divmod?
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form:<built-in function divmod>
Namespace: Python builtin
Docstring:
divmod(x, y) -> (div, mod)
Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x.
[9]中的:divmod?
类型:内置函数或方法
基类:
字符串形式:
名称空间:Python内置
文档字符串:
divmod(x,y)->(div,mod)
返回元组((x-x%y)/y,x%y)。不变量:div*y+mod==x。
是。因此,据我所知,要“取消”显示“\n”,我应该使用打印,而不是只键入[function]。\uuuu doc\uuuu?是的。它还将删除引号。