python 中 \n 的替代词是什么?
What is the alternate to \n in python?
我想在 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”字符。如何做到这一点?
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."])
这似乎有效:
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.'
])
对于三引号字符串文字,您可以使用实际的换行符而不是 \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.""")
我想在 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”字符。如何做到这一点?
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."])
这似乎有效:
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.'
])
对于三引号字符串文字,您可以使用实际的换行符而不是 \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.""")