473,473 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

return multiple values from fuction

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

??
Jul 18 '05 #1
6 43659
On Thu, 06 Nov 2003 19:58:55 +0000, Lupe <lu***@iname.com> 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
Jul 18 '05 #2
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

Jul 18 '05 #3
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

Jul 18 '05 #4
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

Jul 18 '05 #5
I'm starting with Python and I find it really great!

It's... natural!

Lupe

Jul 18 '05 #6
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
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jaye Gallagher | last post by:
Hi there, I'm coming from a MS-SQL/MySQL background, and am trying to understand the way Postgres phrases "stored procedure" type stuff. What is mystifying me, in particular, is the fact that...
1
by: turtle | last post by:
I need to write an update query that will return the earliest date to a table based on the data of a different table. I have a labor table that looks like this TableLabor JobCode WorkORder ...
4
by: Aaron | last post by:
can a method return multiple values? pseudo code public string method1() { //db pull select col1, col2, from tb1 s1 = col1;
3
by: smen | last post by:
hiye, can stored procedure return multiple @output's? thanks for replying...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
1
by: deepadaffine | last post by:
I am doing a program that calculate velocity and acceleration. I get all my input in main and then i call a sub function giving the input values as parameter and calculate velocity and...
1
by: v4u2chat | last post by:
Do I need to extend any of classes from AXIS to return multiple values? I'm exposing the following method as web service through AXIS to return multiple values. public ContactAddress...
4
by: ashokbio | last post by:
I want to return values of two arguments through a function via same argument. Example: (a, b) = getvalue(x, y) Can anyone help?
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.