Do Python functions know how many requests are being requested?

In Python, do functions perform how many requests are requested? For example, can I get a function that usually returns one output, but if two outputs are requested, it performs an additional calculation and returns this too?

Or is this not a standard way to do this? In this case, it would be nice to avoid an extra function argument that says to provide second input. But I'm interested in learning a standard way to do this.

+4
source share
2 answers

Real and simple answer: None.

Python functions / methods do not know how many requests are requested, since the return tuple is unpacked after the function call.

underscore (_) , , , :

def f():
    return 1, 2, 3

a, b, c = f()  # if you want to use all
a, _, _ = f()  # use only first element in the returned tuple, 'a'
_, b, _ = f()  # use only 'b'

, (_) pylint .

+7

Python 1 .

:

def myfunc():
    return

None. :

def myfunc():
    return 1, 2, 3

(1, 2, 3).

, .

, , . . API, , , , .

+5
source

Source: https://habr.com/ru/post/1628688/


All Articles