Reputation: 2589
I am having a very basic doubt. Consider the following example:
Case 1:
a=[1,2,3]
b=[4,5,6]
a.append(b) #print a will give [1,2,3,4,5,6]
Case 2:
a=[1,2,3]
a.append(a) # print a gives [1,2,3,...]
I understand the .append in python appends the values of the variable to the end of the variable it's appended to. However, i don't understand the behavior of the '...' in the Case 2.
Upvotes: 6
Views: 1227
Reputation: 1863
The dots indicate that a list contains a reference to itself. It just avoids an infinite recursion during the print.
Upvotes: 6