0 votes
1 view
in Python by (20.2k points)
edited ago by

After the lengthy preamble, comes the inevitable question. Which method (do you think) is best?

I've typically found myself going the dictionary route because it involves less set-up work. From the perspective of a type, however, you might be better off going the class route, since that may help you avoid confusing what a dictionary represents.

On the other hand, there are some in the Python community that feel implied interfaces should be preferred to explicit interfaces, at which point the type of the object really isn't relevant since you're basically relying on the convention that the same attribute will always have the same meaning.

So, how do -you- return multiple values in Python?

1 Answer

0 votes
by (50.5k points)
edited ago by
 
Best answer

To return multiple values from a function:-

import collections 

Point = collections.namedtuple('Point', ['x', 'y']) 

p = Point(1, y=2) 

p.x, p.y 

1 2 

p[0], p[1] 

1 2

...