0
costs = [1,3,5,7,9]
costs1 = costs

costs1.append(costs)

print(f"Output 1 : {costs}")
print(f"Output 2 : {costs1}")


# output 1 : [1, 3, 5, 7, 9, [...]]
# output 2 : [1, 3, 5, 7, 9, [...]]

What does [...] mean in the output???Can anyone please explain this

  • 1
    Welcome to Stack Overflow. Did you expect `costs1 = costs` to copy the list? It does not. Therefore, `costs1` and `costs` are two names for *the same list*, and `costs1.append(costs)` puts the list as an element *into itself*. Yes, Python supports this. However, it cannot then print out the list without some kind of elision, for reasons that I hope are obvious. – Karl Knechtel May 28 '22 at 04:02

0 Answers0