0

In the below code, how is it repeatedly appending itself , when it is not in the loop?

nums = [1, 2, 3] print(nums) # Making the list recursive. nums.append(nums) print(nums is nums[3]) print(nums[3][3][3][3])

27th Jun 2020, 4:35 AM
Gowtham Subramaniyan
Gowtham Subramaniyan - avatar
3 RĂ©ponses
0
𝐊𝐱𝐱𝐛𝐹 𝐆𝐡𝐚đČđšđ„ is it a special case in python that if we use a.append(a) it produces recursive list instead of just appending only once ,the list a to the already existing list. I mean to ask Like a=[1,2] a.append(a) instead of printing [1,2,[1,2]] Is it a special case that it will keep on appending [1,2,[1,2,[1,2,[....]]]] and so on?
27th Jun 2020, 5:49 AM
Gowtham Subramaniyan
Gowtham Subramaniyan - avatar