473,387 Members | 1,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 43656
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.