33

This is a list of Integers and this is how they are printing:

[7, 7, 7, 7]

I want them to simply print like this:

7777

I don't want brackets, commas or quotes. What to do?

4

5 回答 5

77

如果您使用的是 Python 3 或适当的 Python 2.x 版本,from __future__ import print_function则:

data = [7, 7, 7, 7]
print(*data, sep='')

否则,您需要转换为字符串并打印:

print ''.join(map(str, data))
于 2013-07-20T00:50:18.933 回答
15

Try this:

print("".join(str(x) for x in This))
于 2013-07-20T00:35:54.757 回答
9

.format从 Python 2.6 及更高版本使用:

>>> print '{}{}{}{}'.format(*[7,7,7,7])
7777
>>> data = [7, 7, 7, 7] * 3
>>> print ('{}'*len(data)).format(*data)
777777777777777777777777

对于 Python 3:

>>> print(('{}'*len(data)).format(*data))
777777777777777777777777
于 2013-07-20T02:15:29.960 回答
6

您可以将其转换为字符串,然后转换为 int:

print(int("".join(str(x) for x in [7,7,7,7])))
于 2013-07-20T00:44:11.517 回答
2

Something like this should do it:

for element in list_:
   sys.stdout.write(str(element))
于 2013-07-20T00:36:51.193 回答