0

Sorry for the very messy title. What I have is a function that returns 2 different values:

def func(name):

return value1, value2

Now I would like to assign these 2 values to variables in one line. This is what I have tried:

x,y = func(name)[0] , [1]

The x variable is assigned correctly, but the y variable is assigned just assigned as [1].
If it relevant: The [0] is an array and the [1] is a DataFrame form a .csv file.

1 Answer 1

1

You are close. It's even simpler than you think, you can extract without reference to indices:

def func(name):
    # do something
    return value1, value2

x, y = func(var)

func returns a tuple (note parentheses are not required). You can then unpack via sequence unpacking. I would advise you choose variable names that are informative.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.