# P4.2 Python Tuples: List ऐवजी Tuple कधी वापरायचा?

Source: https://ravindrabagale.com/mr/datascience/py04-python-lists-tuples-dictionaries-and-sets-with-examples/p4-2-python-tuples-when-to-use-a-tuple-instead-of-a.html
Language: mr (Marathi with English technical terms)

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

काही values कधीच बदलू नयेत — latitude-longitude, (city, pincode). त्यासाठी tuple सुरक्षित आहे.

हे काय आहे?

Tuple म्हणजे ( ) मधल्या values ज्या बदलता येत नाहीत. Unpacking ने tuple च्या values एकदम वेगवेगळ्या variables मध्ये जातात.

कसं करायचं?

Step 1. ( ) मध्ये values लिहा.
Step 2. Index ने वाचा किंवा unpack करा.
Step 3. बदलायचं असेल तर list वापरा.

उदाहरण A: Location साठवा

```python
hub = (25.2048, 55.2708)
print(hub[0])
print(hub[1])
```

Output:

```text
25.2048
55.2708
```

याचा अर्थ: Tuple index ने list सारखाच वाचता येतो.

उदाहरण B: Tuple unpack करा

```python
hub = (25.2048, 55.2708)
lat, lon = hub
print("Lat:", lat, "Lon:", lon)
```

Output:

```text
Lat: 25.2048 Lon: 55.2708
```

याचा अर्थ: a, b = tuple ने दोन्ही values एकदम मिळाल्या.

उदाहरण C: मुद्दाम केलेली error: tuple बदलत नाही

```python
hub = (25.2048, 55.2708)
hub[0] = 26.0
```

Output:

```text
TypeError: 'tuple' object does not support item assignment
```

याचा अर्थ: Tuple मध्ये value बदलायचा प्रयत्न केल्यावर TypeError आला.

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

Function दोन values return करतं तेव्हा Python tuple देतो. pandas मधलं सर्वात सामान्य उदाहरण `rows, cols = df.shape`.
