Python 打印列表的制表符分隔值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4048964/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 14:01:28 来源:igfitidea点击:
printing tab-separated values of a list
提问by max
Here's my current code:
这是我当前的代码:
print(list[0], list[1], list[2], list[3], list[4], sep = '\t')
I'd like to write it better. But
我想写得更好。但
print('\t'.join(list))
won't work because list elements may numbers, other lists, etc., so joinwould complain.
不会工作,因为列表元素可能是数字、其他列表等,所以join会抱怨。
采纳答案by Glenn Maynard
print(*list, sep='\t')
Note that you shouldn't use the word listas a variable name, since it's the name of a builtin type.
请注意,您不应将这个词list用作变量名,因为它是内置类型的名称。
回答by fabrizioM
print('\t'.join(map(str,list)))
回答by cred
print('\t'.join([str(x) for x in list]))

