V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
SkyEcho
V2EX  ›  问与答

python 新手看到一种写法 ((_, p), _) = parsed,请问是什么意思?

  •  1
     
  •   SkyEcho · Dec 16, 2015 · 2741 views
    This topic created in 3785 days ago, the information mentioned may be changed or developed.

    完整代码

    def process_group(parsed):
            ((_, p), _) = parsed
            return p
    

    说这个函数是用来去括号的,这左边到底是个啥? 正则,函数式?怎么表达式还能写左边,看不懂啊。。。。

    3 replies    2015-12-17 09:27:31 +08:00
    c
        1
    c  
       Dec 16, 2015   ❤️ 2
    解包

    >>> parsed = ((1, 2), 3)
    >>> ((_, p), _) = parsed
    >>> p
    2
    linnchord
        2
    linnchord  
       Dec 16, 2015   ❤️ 2
    ```
    >>> a, b = (1, 2)
    >>> print a, b
    1 2

    >>> a, b = ((3, 4), 2)
    >>> print a, b
    (3, 4) 2

    >>> ((a, c), b) = ((3,4), 2)
    >>> print a, b, c
    3 2 4
    ```
    wwxiong
        3
    wwxiong  
       Dec 17, 2015
    元组赋值而已
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6179 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 88ms · UTC 02:37 · PVG 10:37 · LAX 19:37 · JFK 22:37
    ♥ Do have faith in what you're doing.