-4

我想在 python 中打印以下输出:

 99 buckets of bits on the bus.
 99 buckets of bits.
 Take one down, short it to ground.
 98 buckets of bits on the bus.

使用单个打印命令,中间没有“\n”字符。如何才能做到这一点?

4

3 回答 3

5

使用三引号字符串文字,您可以使用实际的换行符而不是\n.

print(""" 99 buckets of bits on the bus.
 99 buckets of bits.
 Take one down, short it to ground.
 98 buckets of bits on the bus.""")
于 2016-09-28T02:41:25.057 回答
3
import os
print os.linesep.join(["99 buckets of bits on the bus.",
 "99 buckets of bits.",
 "Take one down, short it to ground.",
 "98 buckets of bits on the bus."])
于 2016-09-28T02:36:03.650 回答
0

这似乎有效:

print chr(10).join([
    '99 buckets of bits on the bus.',
    '99 buckets of bits.',
    'Take one down, short it to ground.',
    '98 buckets of bits on the bus.'
])
于 2016-09-28T02:38:15.553 回答