Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > return multiple values from fuction

Reply
Thread Tools

return multiple values from fuction

 
 
Jay Dorsey
Guest
Posts: n/a
 
      11-06-2003
Lupe wrote:
> 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 a():

.... return "value 1", "value 2"
....
>>> c, d = a()
>>> c

'value 1'
>>> d

'value 2'
>>> e = a()
>>> e

('value 1', 'value 2')

HTH

Jay


 
Reply With Quote
 
 
 
 
Lupe
Guest
Posts: n/a
 
      11-06-2003
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

??


 
Reply With Quote
 
 
 
 
Jay O'Connor
Guest
Posts: n/a
 
      11-06-2003
On Thu, 06 Nov 2003 19:58:55 +0000, Lupe <(E-Mail Removed)> wrote:

>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


 
Reply With Quote
 
Irmen de Jong
Guest
Posts: n/a
 
      11-06-2003
Lupe wrote:
> how can I assign the two return values to two distinct variables, as for ex.


By using tuple unpacking:

(varC, varD) = function()


--Irmen

 
Reply With Quote
 
Alex Martelli
Guest
Posts: n/a
 
      11-06-2003
Lupe wrote:

> 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

 
Reply With Quote
 
Irmen de Jong
Guest
Posts: n/a
 
      11-06-2003
Alex Martelli wrote:

>>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

 
Reply With Quote
 
Lupe
Guest
Posts: n/a
 
      11-06-2003
I'm starting with Python and I find it really great!

It's... natural!

Lupe

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
i used lots of static fuction is it ok? mike ASP .Net 3 11-16-2005 03:06 AM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
I'd like to conver long value to IP address, which fuction do I have to use? somez72 Java 4 05-03-2004 09:27 PM
An allocated variable returning by a fuction is unallocated automatically ? orion30 C++ 2 07-14-2003 10:39 AM
Re: reverse Fuction "Segmentation fault" MiniDisc_2k2 C++ 2 07-03-2003 02:52 PM



Advertisments