V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
louhang
V2EX  ›  Python

python3 以后的特性 ...只是占位?

  •  
  •   louhang · 2019-07-19 11:38:51 +08:00 · 2124 次点击
    这是一个创建于 1741 天前的主题,其中的信息可能已经有所发展或是发生改变。

    返回值 None

    def test(): ...

    返回值 None

    def test(): pass

    返回值都一样,这个三个点和 pass 区别在哪呢?都是占位的吗?

    4 条回复    2019-07-19 12:03:31 +08:00
    blacklinux
        1
    blacklinux  
       2019-07-19 11:52:25 +08:00
    Ellipsis 对象
    siteshen
        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.
    Trim21
        3
    Trim21  
       2019-07-19 11:57:28 +08:00
    ...是个特别的量,第一个例子里面换成随便 123 或者"123"都一样,函数里面没有返回值所以返回了 None
    louhang
        4
    louhang  
    OP
       2019-07-19 12:03:31 +08:00
    @blacklinux
    @siteshen
    @Trim21 感谢,刚刚去看过文档没看到那块所以才提问的。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   950 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:21 · PVG 05:21 · LAX 14:21 · JFK 17:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.