# Dictionany

Dictionary cũng là một cấu trúc mảng, nhưng các phần tử bao gồm key và value. Nếu bạn có biết JSON thì cấu trúc Dictionary tương tự như một object json. Một Dictionary được khai báo bằng cặp dấu ngoặc `{...}`.

#### Ví dụ:

```python
point = {'x': 1, 'y': 2}
```

Truy xuất một giá trị dựa vào key của đối tượng.

#### Ví dụ:

```python
point = {'x': 3, 'y': 6, 'z' : 9}

print point[x]
# Hiển thị 3
```

## Thêm một phần tử

Để thêm một phần tử vào đối tượng đã khai báo, sử dụng cấu trúc `dict[key] = value`.

#### Ví dụ:

```python
user = {'name': 'Jone', 'age': 30}
user['country'] = 'Vietnam'
print user
# Hiển thị {'country': 'Vietnam', 'age': 30, 'name': 'Jone'}
```

## Một số hàm, phương thức thông dụng:

* `dict.clear()` Xóa toàn bộ dữ liệu bên trong đối tượng
* `dict.copy()` Trả về một bản copy của đối tượng
* `dict.fromkeys(seq[, value])` Tạo một đối tượng với danh sách `key` từ seq và nếu có truyền `value` thì lấy đó làm giá trị cho các phần tử.
* `dict.has_key(key)` kiểm tra một key có tồn tại trong đối tượng hay không.
* `dict.keys()` Trả về một List chứa các key
* `dict.values()` Trả về một List chứa các value

## Follower me

* **Facebook**: [https://www.facebook.com/lamsaodecode](https://www.facebook.com/100013678592616)
* **Blog:** <https://lamsaodecode.blogspot.com>
* **Github:** <https://lamsaodecode.github.io/introduction>


---

# 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://lamsaodecode.gitbook.io/python-reference/dictionany.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.
