2

I'm working with an API that returns variables in this format:

[x, y]

How can I take that and turn it into individual x and y variables?

user3147697
  • 91
  • 1
  • 9
  • 1
    you could do first, second = –  Dec 30 '13 at 21:56
  • 3
    Take a look at the Python documentation before posting a question like this. The internet is filled with plenty of excellent resources regarding learning Python. – motoku Dec 30 '13 at 22:02

3 Answers3

8
>>> a,b = [1, 2]
>>> a
1
>>> b
2
uselpa
  • 18,732
  • 2
  • 34
  • 52
4

You could do

first, second = somethingReturned

1

If you are passing the data you retrieve from your API to another function, you don't have to unpack them by hand, just use the star operator.

my_func(*api_func())
Steinar Lima
  • 7,644
  • 2
  • 39
  • 40