qiuyouzhi 发表于 2020-4-21 15:52:35

Python 位置参数与关键字参数

这是一封信件:

Python already allows positional arguments after keyword
arguments:

    py> sorted(reverse=True, *(,))
   
   
Haha, that's very clever. I had to think for a bit about why that's allowed. So let me specify: we don't allow non-variadic positional arguments after keyword arguments, and I don't think we ever will or should.

I have an actual, concrete possible enhancement in mind: relaxing the
restriction on parameter order.

What? Do you think that the current restriction is bad, and we should just drop it? Why?

啥意思呢?

其实,光看这一部分:

py> sorted(reverse=True, *(,)) # 这里加个逗号,是为了保证它是一个可迭代对象,而不是4个数


!!!Python居然允许关键字参数在位置参数前面了!

我自己试了试,也是可以的!

各位觉得这是一件好事还是坏事呢?

永恒的蓝色梦想 发表于 2020-4-21 16:13:04

这是一件怪事

zltzlt 发表于 2020-4-21 19:52:13

永恒的蓝色梦想 发表于 2020-4-21 16:13
这是一件怪事

+1

_2_ 发表于 2020-4-21 20:07:35

永恒的蓝色梦想 发表于 2020-4-21 16:13
这是一件怪事

……说你杠精不过分吧

hrp 发表于 2020-4-21 20:11:06

这是什么原理

永恒的蓝色梦想 发表于 2020-4-21 20:12:39

_2_ 发表于 2020-4-21 20:07
……说你杠精不过分吧

信中说了,这是不应该出现的

_2_ 发表于 2020-4-21 20:16:58

永恒的蓝色梦想 发表于 2020-4-21 20:12
信中说了,这是不应该出现的

那我就不知道了……

_2_ 发表于 2020-4-21 20:19:10

永恒的蓝色梦想 发表于 2020-4-21 20:12
信中说了,这是不应该出现的

原文译文:
我不得不思考一下为什么这是允许的。所以让我具体说明一下 :
我们不允许关键字参数后的非变量位置参数,我认为我们永远不会或应该。
我有一个实际的、具体的可能 :
放松对参数顺序的限制。
什么?你认为目前的限制不好,我们应该放弃它吗?为什么?
页: [1]
查看完整版本: Python 位置参数与关键字参数