# P7.4 अनेक Values Return करणं आणि Local Variables

Source: https://ravindrabagale.com/mr/datascience/py07-python-functions-tutorial-def-return-arguments-and-lambda/p7-4-return-multiple-values-and-local-variables-in.html
Language: mr (Marathi with English technical terms)

हे का शिकायचं?

Total आणि सरासरी दोन्ही एकाच function मधून हवे असतात.

हे काय आहे?

return a, b दोन values tuple म्हणून देतो, त्या unpack करता येतात. Function आतले variables बाहेर दिसत नाहीत (local).

कसं करायचं?

Step 1. return a, b लिहा.
Step 2. x, y = f() ने unpack करा.

उदाहरण A: Total आणि सरासरी

```python
def summary(values):
    total = sum(values)
    avg = total / len(values)
    return total, round(avg, 2)

t, a = summary([4200, 3900, 5100, 4800])
print(t, a)
```

Output:

```text
18000 4500.0
```

याचा अर्थ: दोन्ही values एकदम मिळाल्या.

उदाहरण B: Local variables आतच राहतात

```python
def calc():
    inside = 10
    return inside

calc()
print(inside)
```

Output:

```text
NameError: name 'inside' is not defined
```

याचा अर्थ: Function आतला variable बाहेर वापरला तर NameError येतो.

रवींद्र बागले यांची tip

Data parameters मधून आत द्या आणि return मधून बाहेर घ्या. Functions मध्ये global variables बदलणं टाळा.
