在不使用join命令的情况下联接列表中的元素

问题描述:

我需要在不使用连接命令的情况下将列表中的元素连接 ,因此,例如,如果我有该列表:

I need to join the elements in a list without using the join command, so if for example I have the list:

[12,4,15,11]

输出应为:

1241511

到目前为止,这是我的代码:

Here is my code so far:

def lists(list1):
    answer = 0
    h = len(list1)
    while list1 != []:
        answer = answer + list1[0] * 10 ** h
        h = h - 1
        list1.pop(0)
    print(answer)

但是,最后,答案最终是125610,这显然是错误的.

But, in the end, the answer ends up being 125610 which is clearly wrong.

我认为逻辑还可以,但是我找不到问题所在?

I think the logic is OK, but I can't find the problem?

如果您只想打印数字而不是return实际的int:

If you just want to print the number rather than return an actual int:

>>> a = [12,4,15,11]
>>> print(*a, sep='')
1241511