因此,当我试图打印Python函数的帮助/信息function.__doc__
时,当文档字符串中出现\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,UbuntuwithPython2.7上试过了。
看起来你检查了交互shell中的对象,而不是打印它。如果你是指印刷品,就写下来。
在Python3.x中,print是一个普通函数,因此必须使用()。以下(推荐)在2.x和3.x中都适用:
但我建议你用
或者在伊普顿
您可能会发现使用
help(divmod)
而不是divmod.__doc__
更有帮助。相关问题 更多 >
编程相关推荐