Thus, in the function, adding a to the set is not displayed, but does this happen if not in the function?
No, this is not what is happening.
It happens that when you do mylist = mylist + [6] you actually create a completely new list and put it in the local variable mylist . This mylist variable will disappear after the function is executed, and the newly created list will also disappear.
OTOH, when you execute mylist.append(6) , you are not creating a new list. You get the list already in the mylist variable and add a new element to the same list. As a result, the list (which is indicated by the symbol list2 too) will be changed by itself. The mylist variable will disappear again, but in this case you have changed the original list.
Let's see if a more visual explanation helps you :)
What happens when you call proc()
When you write list1 = [1, 2, 3, 4, 5] , you create a new list object (on the right side of the equal sign) and create a new variable list1 that points to this object.

Then, when you call proc() , you create a new new variable mylist , and since you pass list1 as a parameter, mylist will point to the same object:

However, the operation mylist + [6] creates a whole new list object, the contents of which are the contents of the object that mylist points mylist , plus the contents of the next list object, that is, [6] . Since you are binding this new object to mylist , our script changes a bit, and mylist no longer points to the same object that list1 points list1 :

I did not say that mylist is a local variable: it will disappear after the proc() function ends. So, when the completion of proc() ended, mylist went away:

Since no other variable points to the object generated by mylist + [6] , it will also disappear (since the garbage collector * will collect it):

Note that at the end, the object pointed to by list1 does not change.
What happens when you call proc2()
Everything changes when you call proc2() . At first itβs the same thing: you create a list ...

... and pass it as a parameter to the function that will generate the local variable:

However, instead of using the concatenation operator + , which generates a new list, you apply the append() method to the existing list. The append() method does not create a new object; instead, it changes the existing one:

After the function finishes, the local variable will disappear, but the original object that it points to and list1 will already be changed:

Since it is still listed by list1 , the original list is not destroyed.
EDIT : if you want to take a look at all this that happens before your eyes , just go to this radically amazing simulator :

* If you do not know what a garbage collector is ... well, you will immediately know your own question.