def test(): ...
def test(): pass
返回值都一样,这个三个点和 pass 区别在哪呢?都是占位的吗?
1
blacklinux 2019-07-19 11:52:25 +08:00
Ellipsis 对象
|
2
siteshen 2019-07-19 11:55:00 +08:00 1
以后遇到这种疑问,可以先去查一下 `...` 的含义:
https://docs.python.org/3/library/constants.html#Ellipsis `...` 是个常量对象,在你这种场景下,换成 123 效果也一样。 $ python3 -c 'a = ...; print(a)' Ellipsis $ python3 -c 'help(...)' Help on ellipsis object: class ellipsis(object) | Methods defined here: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) from builtins.type | Create and return a new object. See help(type) for accurate signature. |
3
Trim21 2019-07-19 11:57:28 +08:00
...是个特别的量,第一个例子里面换成随便 123 或者"123"都一样,函数里面没有返回值所以返回了 None
|
4
louhang OP |