Why the “mutable default argument fix” syntax is so ugly, asks python newbie

前端 未结 8 645
悲&欢浪女
悲&欢浪女 2020-11-30 09:00

Now following my series of \"python newbie questions\" and based on another question.

Prerogative

Go to http://python.net/~goodger/projects/pyco

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 09:06

    Probably you should not define these two functions as good and bad. You can use the first one with list or dictionaries to implement in place modifications of the corresponding objects. This method can give you headaches if you do not know how mutable objects work but given you known what you are doing it is OK in my opinion.

    So you have two different methods to pass parameters providing different behaviors. And this is good, I would not change it.

提交回复
热议问题