# Разница между списком и кортежем

### **1. Основные отличия**

| Характеристика         | Список (`list`)                           | Кортеж (`tuple`)                           |
| ---------------------- | ----------------------------------------- | ------------------------------------------ |
| **Изменяемость**       | Изменяемый (`mutable`)                    | Неизменяемый (`immutable`)                 |
| **Синтаксис**          | `[1, 2, 3]`                               | `(1, 2, 3)` или `1, 2, 3`                  |
| **Методы**             | `append`, `extend`, `remove`, `pop` и др. | Нет методов для изменения                  |
| **Производительность** | Медленнее из-за изменяемости              | Быстрее при доступе к элементам            |
| **Использование**      | Когда нужен **модифицируемый контейнер**  | Когда нужен **фиксированный набор данных** |

***

### **2. Примеры**

#### **2.1 Список**

```python
lst = [1, 2, 3]
lst.append(4)
lst[0] = 10
print(lst)  # [10, 2, 3, 4]
```

#### **2.2 Кортеж**

```python
tup = (1, 2, 3)
# tup[0] = 10  # TypeError: 'tuple' object does not support item assignment
print(tup)   # (1, 2, 3)
```

***

### **3. Когда использовать**

* **Список**: тестовые данные, изменяемые коллекции, динамические структуры.
* **Кортеж**: координаты, фиксированные конфигурации, ключи словаря (так как кортеж **хэшируемый**).

***

### **4. Применение в автотестах**

* **Список**:

  ```python
  test_data = [("user1", "pass1"), ("user2", "pass2")]
  for username, password in test_data:
      assert login(username, password)
  ```
* **Кортеж**:

  ```python
  coordinates = (10, 20)  # фиксированная точка на UI
  assert move_to(coordinates)
  ```

***

💡 **Вывод:**

* `list` = изменяемый контейнер, много методов для модификации.
* `tuple` = неизменяемый контейнер, быстрее и безопаснее для фиксированных данных.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kaze.gitbook.io/qa-theory/osnovy-programmirovaniya-na-python/raznica-mezhdu-spiskom-i-kortezhem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
