Limit the number of values ​​returned by a Python function / method

I worked with some code and realized that everything became much simpler when one method returned 4 values. Working with such traditional languages ​​as C ++ and Java, where methods return only one value, I came to surprise

Is there a limit on the number of values ​​returned by a Python function?

Such things work effortlessly. Is there a limit?

def hello():
    return 1, 2, 3, 4, 5

a, b, c, d, e = hello()
print a, b, c, d, e


Roughly enough, I did not find the answer to this question

+4
source share
2 answers

If you return multiple values, you are actually returning a tuple . Really:

return 1,4,2,5

abbreviated for:

return (1,4,2,5)

, , . :

import sys

sys.maxsize

2 31 -1 = 2 147 483 647 32- 2 63 -1 = 9 223 372 036 854 775 807 64- . : 2 32 -1 ( 2 64 -1), , , 32- , 4 GiB , (, ).

, : , .

+7

Python : . , ( return 1, 2, 3, 4, 5). .

+6

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


All Articles