Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 207

Best way to use only one of multiple return values: indexing or unpacking assignment [duplicate]

$
0
0

Given some function with more than one return value, e.g.

def example():    return 1, 2

One could access only one of these values in different ways; for instance

Option A:

val = example()[0]

Option B:

val, _ = example()

and of course more elaborate, more fancy and supposedly (!) more inefficient ways like

Option C:

val = list(example()).pop(0)

I understand what these codes are doing from a programming point of view. However, I do not know the computer mechanics behind each of these options (how these values are stored, returned, restored etc). So the question is, what would be the best way -- in terms of efficiency, computational time, storage resources or similar parameters -- to only retrieve one of these return values and why?


Viewing all articles
Browse latest Browse all 207

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>