> For the complete documentation index, see [llms.txt](https://timosii.gitbook.io/py_tutorial/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://timosii.gitbook.io/py_tutorial/stroki.-spiski/izmenyaemye-i-neizmenyaemye-obekty-v-python.md).

# Изменяемые и неизменяемые объекты в Python\*

* Переменные в Python — это ссылки на объекты в памяти компьютера
* Каждый объект в памяти имеет:
  * *идентификатор* : адрес в оперативной памяти компьютера
  * *тип* : строка, число, список и т.д
  * *значение*

```python
name = "Sergey"
id(name) # узнать идентификатор объекта
~# 140291548567088
```

* В момент определения переменной создаётся объект в памяти компьютера, затем ему присваивается ссылка — имя переменной
* Объекты могут быть изменяемые(например: списки) и неизменяемые(например: строки, числа)

```python
c = 5 # c - ссылка на объект число 5
d = c # создадим ещё одну ссылку на этот же объект

c += 1 # добавим 1 к c - теперь c ссылаетcя на ДРУГОЙ объект: число 6
c == 6 # True
d == 5 # True

a = [42] # a - ссылка на объект - список из одного элемента
b = a # создадим еще одну ссылку на этот же объект

a.append(5) # изменим ОБЪЕКТ - добавим элемент
a == [42, 5] # True
b == [42, 5] # True - b тоже изменилась, т.к. список это изменяемый объект
```

*В итоге мы получим такую картину: в памяти у нас остался один объект: список и два объекта* — *целые числа*&#x20;

<figure><img src="/files/Ay4nwn3NKLLAoflakYno" alt=""><figcaption></figcaption></figure>

* Оператор is сравнивает объекты по адресам, т.е. проверяет, ***СОВПАДАЮТ*** ли объекты. Оператор == сравнивает ***РАВНЫ*** ли объекты

***Практика:***

* Повторите код из занятия. Проверьте, совпадают ли `a` и `b`, `c` и `d`. На каждом этапе программы посмотрите идентификаторы объектов.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://timosii.gitbook.io/py_tutorial/stroki.-spiski/izmenyaemye-i-neizmenyaemye-obekty-v-python.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.
