简体   繁体   中英

Making multiple variables equal to multiple values from a list

Is there a way I can use something like this:

a, b, c = [1, 2, 3, 4, 5]

In order to get the values:

a = 1
b = [2, 3]
c = [4, 5]

To break up existing data as needed:

>>> data = [1,2,3,4,5]
>>> a,b,c = data[0],data[1:3],data[3:]
>>> a
1
>>> b
[2, 3]
>>> c
[4, 5]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM