假设我想要这样打印:
print 1,"hello", 2, "fart"
在Python 2中,使用制表符而不是空格的最Pythonic方法是什么?
这是一个非常愚蠢的问题,但我似乎找不到答案!
# Available since Python 2.6
from __future__ import print_function
# Now you can use Python 3's print
print(1, 'hello', 2, 'fart', sep='\t')
str.join
方法:print '\t'.join(map(str, (1, "hello", 2, "fart")))
Traceback (most recent call last): File "<pyshell#148>", line 1, in <module> print '\t'.join((1, "hello", 2, "fart"))d TypeError: sequence item 0: expected string, int found
- eye_mewprint '\t'.join((str(i) for i in (1, "hello", 2, "fart")))