推荐学习书目
› 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
chaleaoch
V2EX  ›  Python

我...问个问题, 正文中的 Python 代码. 为什么可以正确执行?

  •  
  •   chaleaoch · Dec 26, 2020 · 2877 views
    This topic created in 2143 days ago, the information mentioned may be changed or developed.
    def test_func(a, /, b):
        print(a, b)
    
    
    test_func(1, 2)
    

    函数参数中的 / 是个啥? black 和 flake8 都提示异常,但是确实是可以正确执行的. python 3.9

    jdhao
    jdhao
    Dec 26, 2020 via Android
    1
    不懂,没见过,楼下回答
    chaleaoch
    chaleaoch
    OP
    Dec 26, 2020
    2
    查到了. 仅限位置参数.
    renmu123
    renmu123
    Dec 26, 2020 via Android
    4
    3.7 还是 3.8 加入的新语法
    abersheeran
    abersheeran
    Dec 26, 2020❤️3
    5
    / 之前的参数都不能以 name=value 这种形式传参。

    与之类似功能的是 def f(a, *, b): ... * 之后的都必须以 name=value 的形式传参。
    XIVN1987
    XIVN1987
    Dec 26, 2020
    6
    @abersheeran
    前者是 pos-only
    后者是 kw-only
    crayygy
    crayygy
    Dec 27, 2020 via Android
    7
    Python 3.6 3.7 3.8 好像都有一些新增的语法,之前遇到过一次脚本是基于 3.6 写的,结果在 Ubuntu 16.04(预装的 Python 3.5 以下的)就怎么也跑不过,查了以后才知道
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1593 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:51 · PVG 20:51 · LAX 04:51 · JFK 07:51
    ♥ Do have faith in what you're doing.