Bis*_*aul 0 python tabs newline python-3.x
我是Python的新手,今天我正在基于列表在Python3.3上编写一个简单的测试程序.所以,我注意到当我输入制表空间字符时\t
,输出被闪现,这样我就已经投入了新行字符!下面给出了一个样本:
def printlist(list_name,tabs=0):
for items in list_name:
if isinstance(items,list):
printlist(items,tabs)
else:
print(items)
for num in range(tabs):
print('\t') #tab-stops provide
list3 = [
'list no. 3',
['tree','stems','root'],
['human','hand','leg'],
['robot','microprocessor','motor']
]
printlist(list3,1)
Run Code Online (Sandbox Code Playgroud)
输出是:
>>> ================================ RESTART ================================
>>>
list no. 3
tree
stems
root
human
hand
leg
robot
microprocessor
motor
>>>
Run Code Online (Sandbox Code Playgroud)
但我想要的输出格式是:
list no. 3
tree
stems
root
human
hand
leg
robot
microprocessor
motor
Run Code Online (Sandbox Code Playgroud)
[ 我希望标签不是新行 ]
那怎么可能呢?
默认情况下,print()
将以换行符结束.如果要抑制此行为,请指定end
.
print("\t", end="")
Run Code Online (Sandbox Code Playgroud)
文档在这里. http://docs.python.org/3.3/library/functions.html#print
归档时间: |
|
查看次数: |
186 次 |
最近记录: |