Avoid Side Effects When Using List in a Function

When using a Python list as an argument in a function, you might inadvertently change its value. For example, in the code above, using the append method ends up changing the values of the original list. 

If you want to avoid this side effect, use copy with a list or deepcopy with a nested list in a function. 

My previous tips on good Python practices.

Scroll to Top

Work with Khuyen Tran

Work with Khuyen Tran