Help with this code not able to understand output

Hey @sarthaktech23, what should be the output according to you ?

list1 = [10,โ€™โ€™] list2 = [123] list3 = [ โ€˜aโ€™]

Okay @sarthaktech23, one thing that should note here is that when list1 is created in the 5th line, the list gets a value of 10. When you create list2 in the 6th line, itโ€™s easy to understand that we are sending our own empty list along with the 123, an hence list2 contains the element 123. But now when we create list3 in the 7th line, you must note that since we are not sending any default empty list in the function call ( we are just sending a single element โ€˜aโ€™) , the letter โ€˜aโ€™ gets appended to the same list that was created when we had created list1. Thatโ€™s the reason when you print the final output of all the three lists, you get something like this

[10, 'a']
[123]
[10, 'a']

list1 and list3 are the same lists.

I hope this clears your doubt ! :slight_smile:
Happy Coding !

1 Like

I hope Iโ€™ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.