我要打印的下面的輸出在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」個字符。如何才能做到這一點?
我要打印的下面的輸出在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」個字符。如何才能做到這一點?
隨着三引號字符串常量,你可以用它代替\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.""")
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.'
])
如果你想換行,你必須把它們放在那裏...你怎麼能期望程序只是猜測你想換行符? –
您是否將範圍(10)中的i:print(i)'作爲單個打印命令或十個打印命令?如果你使用三重引號字符串,並且有換行符,但它們是隱含的,那麼怎麼辦? – TessellatingHeckler
我認爲更好的問題是爲什麼 –