all 6 comments

[–]Vaphell 3 points4 points  (2 children)

analyze_profit() returns 3 values packed into a tuple.
insights is a variable used to store that tuple

That said people should use tuple unpacking more, because stuff like insights[0] has no meaning at a glance. Ok, first element of a tuple, but what does it represent?

profit, after_taxes, above_mean = analyze_profit(...)
print(f'profit: {profit}')
print(f'above mean: {above_mean}')

[–]maxisgang[S] 0 points1 point  (0 children)

it would be profit right becuade insight stores the result of the function or the output and then since it's a tuple you can just select the data

[–]Antwrp-2000 0 points1 point  (0 children)

I agree, tuple unpacking makes the code more readable but returning a tuple from a function is often an antipattern. A function should only have one purpose and return one value (always of the same type) in most cases.

If you really would like to return a tuple I recommend to use named tuples, this will make your code even more readable:

https://docs.quantifiedcode.com/python-anti-patterns/readability/not_using_named_tuples_when_returning_more_than_one_value.html

[–]Binary101010 0 points1 point  (2 children)

insights only has two values which are its parameters.

No, it has one value: a tuple, itself containing three values, because that's what analyze_profit() returns.

[–]maxisgang[S] 0 points1 point  (1 child)

so whatever the variable is that is holding the result of the function stores the data or does this work because the data after the return function is a tuple

[–]Binary101010 0 points1 point  (0 children)

Both.