如何打印不带括号、逗号和引号的整数列表?

2022-01-31 00:00:00 python python-3.x python-2.7

问题描述

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?

解决方案

If you're using Python 3, or appropriate Python 2.x version with from __future__ import print_function then:

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

Otherwise, you'll need to convert to string and print:

print ''.join(map(str, data))

相关文章