编写一个接受字符串列表并将它们连接起来的函数

Write a function that accepts a list of strings and concatenates them

Write a function called concat() that takes a list of strings as an argument and returns a single string that is all the items in the list concatenated (put side by side). (Note that you may not use the join() function.)

Sample run:

print( concat(['a', 'bcd', 'e', 'fg']) )
abcdefg

在Python中,您可以只使用+运算符连接两个字符串。在你的情况下,你可以这样做:

def concat(list_args):
    res = ""
    for w in list_args:
        res += w
    return res

那么如果你运行

print(concat(['a', 'bcd', 'e', 'fg']))

你得到abcdefg