default argument value is mutable

ast nomail at com.invalid
Fri Oct 7 07:59:37 EDT 2016


"Daiyue Weng" <daiyueweng at gmail.com> a écrit dans le message de 
news:mailman.208.1475840291.30834.python-list at python.org...
> Hi, I declare two parameters for a function with default values [],
>
> def one_function(arg, arg1=[], arg2=[]):
>
> PyCharm warns me:
>
> Default argument value is mutable,
>
> what does it mean? and how to fix it?
>
> cheers

You could ignore this warning if you know what you
are doing, imho.
The default value being mutable it is possible to change
it inside the function. eg:

def test(x=[0]):
... print(x)
... x[0] += 1

>>> test()
[0]

>>> test()
[1]







More information about the Python-list mailing list