# Boolean и их особенности

### **1. Что такое Boolean**

* **Boolean (`bool`)** — это тип данных, который принимает **два значения**:
  * `True` — истина
  * `False` — ложь
* Используется в **условных выражениях, циклах, проверках и логических операциях**.

***

### **2. Особенности Boolean в Python**

1. **Подкласс `int`**
   * `True` ведёт себя как `1`, а `False` как `0`

```python
print(True + 2)   # 3
print(False * 10) # 0
```

2. **Приведение других типов к `bool`**
   * Любое значение можно преобразовать в `True` или `False` через `bool()`

```python
bool(0)       # False
bool(1)       # True
bool("")      # False
bool("text")  # True
bool([])      # False
bool([1,2])   # True
```

3. **Использование в условиях**

```python
x = 10
if x > 5:
    print("x больше 5")  # True → выполняется
```

4. **Логические операции**\
   \| Операция | Пример |\
   \|----------|--------|\
   \| `and` | `True and False` → False |\
   \| `or` | `True or False` → True |\
   \| `not` | `not True` → False |

***

### **3. Примеры применения в автотестах**

* **Проверка условий**

```python
def test_login_success():
    assert login("user", "pass") == True
```

* **Фильтрация данных**

```python
users = [{"name": "Alice", "active": True}, {"name": "Bob", "active": False}]
active_users = list(filter(lambda u: u["active"], users))
print(active_users)  # [{'name': 'Alice', 'active': True}]
```

* **Логические проверки на UI или API**

```python
assert checkbox.is_selected() is True
assert "success" in response.text
```

***

💡 **Вывод:**

* Boolean = True/False, подкласс int, работает с логическими операциями.
* Применяется для **условий, проверок, фильтрации и логики автотестов**.
* Важно понимать **приведение типов к `bool`**, чтобы корректно обрабатывать данные.


---

# 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/boolean-i-ikh-osobennosti.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.
