Forced naming of parameters in Python

后端 未结 11 1305
日久生厌
日久生厌 2020-11-27 12:15

In Python you may have a function definition:

def info(object, spacing=10, collapse=1)

which could be called in any of the following ways:<

11条回答
  •  孤街浪徒
    2020-11-27 13:09

    I don't get why a programmer will add a parameter in between two others in the first place.

    If you want the function parameters to be used with names (e.g. info(spacing=15, object=odbchelper) ) then it shouldn't matter what order they are defined in, so you might as well put the new parameters at the end.

    If you do want the order to matter then can't expect anything to work if you change it!

提交回复
热议问题