只需要打印:
0123456789
而不是这个,与列表大小无关:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
以下是代码示例:
c = []
for x in range(0, 10):
c.append(x)
print c
答案 0 :(得分:3)
您可以使用join
将元素连接在一起,但它们必须是字符串。
map
如果没有>>> ''.join(str(i) for i in range(10))
'0123456789'
,您还可以写:
public class Main {
public static void main(String[] args) {
Thread t = new Thread() {
public void run() {
while (true) {
if (Thread.interrupted()) {
break;
}
}
System.out.println("[thread] exiting...");
}
};
System.out.println("[main] starting the thread");
t.start();
System.out.println("[main] interrupting the secondary thread");
t.interrupt();
try {
t.join();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
System.out.println("[main] exiting");
}
}
答案 1 :(得分:0)
试试这样:
c = []
for x in range(0, 10):
c.append(str(x))
print ''.join(c)