python bài 27

** #Python #Tutorial #Bài27 #Programming #Coding **

** Bài học Python 27: Từ điển **

Trong bài học này, chúng ta sẽ tìm hiểu về từ điển ở Python.Từ điển là một cấu trúc dữ liệu lưu trữ dữ liệu trong các cặp giá trị khóa.Khóa là một định danh duy nhất cho dữ liệu và giá trị là chính dữ liệu.Từ điển rất hữu ích để lưu trữ dữ liệu có liên quan đến nhau.

Để tạo từ điển, bạn sử dụng cú pháp sau:

`` `
Từ điển = {key1: value1, key2: value2, ...}
`` `

Ví dụ: mã sau đây tạo ra một từ điển lưu trữ tên của một số loại trái cây và giá tương ứng của chúng:

`` `
Trái cây = {"Apple": 2.00, "Orange": 1.50, "Chuối": 1.00}
`` `

Bạn có thể truy cập dữ liệu trong từ điển bằng cách sử dụng khóa.Ví dụ: mã sau in giá của một quả táo:

`` `
In (trái cây ["Apple"])
`` `

Bạn cũng có thể thêm các mục mới vào từ điển bằng cú pháp sau:

`` `
Từ điển [khóa] = giá trị
`` `

Ví dụ: mã sau đây thêm một mục mới vào từ điển trái cây:

`` `
trái cây ["đào"] = 1,25
`` `

Bạn cũng có thể xóa các mục khỏi từ điển bằng cú pháp sau:

`` `
Từ điển Del [khóa]
`` `

Ví dụ: mã sau đây xóa mục "Apple" khỏi từ điển trái cây:

`` `
Del trái cây ["Apple"]
`` `

Từ điển là một cấu trúc dữ liệu rất mạnh mẽ có thể được sử dụng để lưu trữ nhiều loại dữ liệu khác nhau.Chúng rất dễ sử dụng và có thể rất hiệu quả.

** Dưới đây là một số tài nguyên bổ sung mà bạn có thể thấy hữu ích: **

* [Hướng dẫn từ điển Python] (https://www.w3schools.com/python/python_dicesaries.asp)
* [Tài liệu từ điển Python] (https://docs.python.org/3/tutorial/datcate.html#dicesaries)
* [Ví dụ về từ điển Python] (https://www.programiz.com/python-programing/dictionary)
=======================================
**#Python #Tutorial #Lesson27 #Programming #Coding**

**Python Lesson 27: Dictionaries**

In this lesson, we will learn about dictionaries in Python. Dictionaries are a data structure that store data in key-value pairs. The key is a unique identifier for the data, and the value is the data itself. Dictionaries are very useful for storing data that is related to each other.

To create a dictionary, you use the following syntax:

```
dictionary = {key1: value1, key2: value2, ...}
```

For example, the following code creates a dictionary that stores the names of some fruits and their corresponding prices:

```
fruits = {"apple": 2.00, "orange": 1.50, "banana": 1.00}
```

You can access the data in a dictionary by using the key. For example, the following code prints the price of an apple:

```
print(fruits["apple"])
```

You can also add new items to a dictionary using the following syntax:

```
dictionary[key] = value
```

For example, the following code adds a new item to the fruits dictionary:

```
fruits["peach"] = 1.25
```

You can also delete items from a dictionary using the following syntax:

```
del dictionary[key]
```

For example, the following code deletes the "apple" item from the fruits dictionary:

```
del fruits["apple"]
```

Dictionaries are a very powerful data structure that can be used to store a variety of different types of data. They are easy to use and can be very efficient.

**Here are some additional resources that you may find helpful:**

* [Python Dictionaries Tutorial](https://www.w3schools.com/python/python_dictionaries.asp)
* [Python Dictionaries Documentation](https://docs.python.org/3/tutorial/datastructures.html#dictionaries)
* [Python Dictionaries Examples](https://www.programiz.com/python-programming/dictionary)
 
Join ToolsKiemTrieuDoGroup
Back
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock