欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python将序列分解为单独的变量

程序员文章站 2022-03-03 16:09:48
...

python将序列分解为单独的变量

[[email protected] /]# python
Python 2.7.5 (default, Oct 30 2018, 23:45:53)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> p = (3,4)
>>> x,y = p
>>> x
3
>>> y
4
>>>
>>> data = ['ace', 50, 91.9, (2012, 12, 21)]
>>> name, shares, price, date = data
>>> name
'ace'
>>> date
(2012, 12, 21)
>>> name, shares, price, (year, month, day) = data
>>> year
2012
>>> month
12
>>>
>>> s = 'hello'
>>> a,b,c,d,e = s
>>> a
'h'
>>> b
'e'
>>> c
'l'
>>> d
'l'
>>> e
'o'
>>>
>>>
>>> data = ['ace', 50, 91.9, (2012, 12, 21)]
>>> _, shares, price, _ = data
>>> shares
50
>>> price
91.9