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
By using tuple unpacking:
(varC, varD) = function()
--Irmen
> 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
>>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()
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
It's... natural!
Lupe
>>> def a():
... return "value 1", "value 2"
...
>>> c, d = a()
>>> c
'value 1'
>>> d
'value 2'
>>> e = a()
>>> e
('value 1', 'value 2')
HTH
Jay
#- 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 f():
return (1, 2)
>>> (a, b) = f()
>>> a
1
>>> b
2
>>>
. Facundo
I'm starting with Python and I find it really great!
It's... natural!
Lupe