Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python get return values of a function separately

I have a simple function in python. Is it an easy way to get result_1 and result_2 in separate lists? thanks

def add(x, y):
    result_1 = x + y
    result_2 = x*y
    return result_1, result_2

for example for x=5, y=6
something like

 result_1=[11]
 result_2=[30]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Not sure why you would need two lists with single elements but you can define whatever return format you want. I e you can create 2 lists using your results:

def add(x, y):
    result_1 = x + y
    result_2 = x*y
    return [result_1], [result_2]

This will return 2 lists, each consisting of a single element.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading