Is there a better way to code variable number of return arguments?

  • Thread starter Dr. Phillip M. Feldman
  • Start date
D

Dr. Phillip M. Feldman

I currently have a function that uses a list internally but then returns the
list items as separate return
values as follows:

if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on). Is there a cleaner way to accomplish the same thing?
 
P

Paul Rubin

Dr. Phillip M. Feldman said:
if len(result)==1: return result[0]
if len(result)==2: return result[0], result[1]

(and so on). Is there a cleaner way to accomplish the same thing?

That is poor style. Just return the result as a list.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top