return multiple values from fuction

J

Jay Dorsey

Lupe said:
hi, if someone can help me I would be grateful

when I do

def function
kjklj
llklç

return variableA, variableB

how can I assign the two return values to two distinct variables, as for ex.

varC = variableA
varD = variableB
.... return "value 1", "value 2"
....('value 1', 'value 2')

HTH

Jay
 
L

Lupe

hi, if someone can help me I would be grateful

when I do

def function
kjklj
llklç

return variableA, variableB

how can I assign the two return values to two distinct variables, as for ex.

varC = variableA
varD = variableB

??
 
J

Jay O'Connor

hi, if someone can help me I would be grateful

when I do

def function
kjklj
llklç

return variableA, variableB

how can I assign the two return values to two distinct variables, as for ex.

varC = variableA
varD = variableB

??
def test ():
...
return variableA, variableN


varC, vardD = test()

varC will contain variableA
varD ill contain variableB
 
I

Irmen de Jong

Lupe said:
how can I assign the two return values to two distinct variables, as for ex.

By using tuple unpacking:

(varC, varD) = function()


--Irmen
 
A

Alex Martelli

Lupe said:
hi, if someone can help me I would be grateful

when I do

def function

this needs of course to be

def function():
kjklj
llklç

return variableA, variableB

how can I assign the two return values to two distinct variables, as for
ex.

varC = variableA
varD = variableB

"just do it":

varC, varD = function()


Alex
 
I

Irmen de Jong

Alex said:
"just do it":

varC, varD = function()

I like that comment... "just do it"...
I find this is also true for most other things
that you want to do in Python.

"How do I create a mapping between a person's last
name and the list of telephone numbers he/she can be
reached at?" -- "umm.. just do it?"

{ "de Jong": ['234234', '34562363'] }

or whatever ;-)

--Irmen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top