Iuliana Netoi <iuliana.ne...@yahoo.com> added the comment: Now I wrote the same list named my_list inside the function. And I deleted the function argument.When running again and again, the function remains as I defined it. So the console behavior depends on the list placing: before or inside the function. When the list is placed before the function and the function is called again and again, the console adds each time the element "z", enlarging the initial list.When the list is placed inside the function and the function is called again and again, the console does not add elements at all and the list remains as I defined it, so the initial one. ;;;;;;;;;;;;;;;;;;;; #%%def problem2_2(): my_list = ["this","is","my","very","first","list"] my_list.append("z") print(my_list) #%%;;;;;;;;;;;;;;;;;;; Here is the output, with no change in my list: In [1]: def problem2_2(): ...: my_list = ["this","is","my","very","first","list"] ...: my_list.append("z") ...: print(my_list) In [2]: problem2_2()['this', 'is', 'my', 'very', 'first', 'list', 'z'] In [3]: problem2_2()['this', 'is', 'my', 'very', 'first', 'list', 'z'] In [4]: problem2_2()['this', 'is', 'my', 'very', 'first', 'list', 'z'] In [5]: problem2_2()['this', 'is', 'my', 'very', 'first', 'list', 'z'] In [6]:
On Thursday, November 15, 2018, 4:50:53 PM GMT+2, Steven D'Aprano <rep...@bugs.python.org> wrote: Steven D'Aprano <steve+pyt...@pearwood.info> added the comment: I don't understand what you think is the bug. You keep repeatedly appending 'z' to the same list. Why are you surprised that it appends 'z' more than once? If you don't want to append it twice, don't call the function twice. Every time you call the function, it adds another 'z'. That's what the function does. It is working correctly. Can you explain what you think is the bug, because it looks to me like it is working as intended. ---------- nosy: +steven.daprano _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35256> _______________________________________ ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35256> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com