unpack the first two elements in list/tuple

后端 未结 5 1428
小蘑菇
小蘑菇 2020-12-29 01:30

Is there a way in python to do like this:

a, b, = 1, 3, 4, 5

And then:

>>> a
1
>>> b
3

5条回答
  •  悲哀的现实
    2020-12-29 02:01

    You could use _ to represent variables you wanted to "throw away"

    >>> a, b, _ = 1, 3, 4
    >>> a
    1
    >>> b
    3
    

提交回复
热议问题