Bare asterisk in function arguments?

后端 未结 6 1197
孤街浪徒
孤街浪徒 2020-11-22 06:22

What does a bare asterisk in the arguments of a function do?

When I looked at the pickle module, I see this:

pickle.dump(obj, file, protocol=None, *,         


        
6条回答
  •  死守一世寂寞
    2020-11-22 07:25

    Bare * is used to force the caller to use named arguments - so you cannot define a function with * as an argument when you have no following keyword arguments.

    See this answer or Python 3 documentation for more details.

提交回复
热议问题