"Why would it return ['yes']
"
Because you modified the list, example
.
"even though i am not directly changing the variable 'example'."
But you are, you provided the object named by the variable example
to the function. The function modified the object using the object's append
method.
As discussed elsewhere on SO, append
does not create anything new. It modifies an object in place.
See http://stackoverflow.com/questions/1682567/why-does-pythons-list-append-evaluate-to-false, http://stackoverflow.com/questions/2022031/python-append-vs-operator-on-lists-why-do-these-give-different-results, http://stackoverflow.com/questions/1918270/python-lists-append-return-value.
and how could I modify the code so that 'example' is not effected by the function?
What do you mean by that? If you don't want example
to be updated by the function, don't pass it to the function.
If you want the function to create a new list, then write the function to create a new list.