The TypeError function outputs your operation to add the substring i to the welcome line. I believe this is due to the fact that the operation is not supported between the type list and str, as can be seen from the following examples:
['a', 'b']+'2' Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: can only concatenate list (not "str") to list '2'+['a', 'b'] Traceback (most recent call last): File "<input>", line 1, in <module> TypeError: Can't convert 'list' object to str implicitly
There are various answers above that recommend alternative code and use the "join" method. However, although I would include an alternative that uses pure loops:
l = [['A','B'],['C','D']] hello = "" for sublist in l: for element in sublist: hello += str(element) print(hello)
Note that this is probably slower than other methods. In addition, I recommend that you do not use the “list” as the variable name, as it is already used by the class.
source share