CoolFace
Apppublic

rifikaru/python-data-structures-explorer

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
lythuyet.html204 linesDownload Raw Back to root
1<!DOCTYPE html>2<html lang="vi">3<head>4    <meta charset="UTF-8">5    <meta name="viewport" content="width=device-width, initial-scale=1.0">6    <title>Lý Thuyết Cấu Trúc Dữ Liệu Python</title>7    <link rel="stylesheet" href="style.css">8    <script src="https://cdn.tailwindcss.com"></script>9    <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>10</head>11<body class="bg-gray-50">12    <custom-navbar></custom-navbar>13    14    <main class="container mx-auto px-4 py-8">15        <section class="mb-12">16            <h1 class="text-4xl font-bold text-amber-500 mb-6">Lý Thuyết Cấu Trúc Dữ Liệu Python</h1>17            <p class="text-lg text-gray-700 mb-8">Tổng hợp kiến thức cơ bản về các cấu trúc dữ liệu trong Python cùng ví dụ minh họa.</p>18            19            <div class="bg-white p-6 rounded-lg shadow-md mb-8">20                <h2 class="text-2xl font-semibold text-amber-500 mb-4">1. Danh sách (List)</h2>21                <div class="space-y-4">22                    <div class="p-4 bg-amber-50 rounded">23                        <h3 class="font-medium">Đặc điểm:</h3>24                        <ul class="list-disc pl-5 mt-2">25                            <li>Là cấu trúc dữ liệu có thứ tự (ordered)</li>26                            <li>Có thể thay đổi (mutable)</li>27                            <li>Cho phép trùng lặp giá trị</li>28                            <li>Được khai báo bằng dấu ngoặc vuông []</li>29                        </ul>30                    </div>31                    <div class="p-4 bg-amber-50 rounded">32                        <h3 class="font-medium">Ví dụ:</h3>33                        <pre class="bg-gray-100 p-4 rounded overflow-x-auto"><code># Khởi tạo danh sách34ds = [1, 2, 3, "Python", 5.5]35 36# Truy cập phần tử37print(ds[0])  # Output: 138print(ds[-1]) # Output: 5.539 40# Thay đổi giá trị41ds[1] = "Hello"42print(ds)  # Output: [1, 'Hello', 3, 'Python', 5.5]</code></pre>43                    </div>44                </div>45            </div>46 47            <div class="bg-white p-6 rounded-lg shadow-md mb-8">48                <h2 class="text-2xl font-semibold text-amber-500 mb-4">2. Tuple</h2>49                <div class="space-y-4">50                    <div class="p-4 bg-amber-50 rounded">51                        <h3 class="font-medium">Đặc điểm:</h3>52                        <ul class="list-disc pl-5 mt-2">53                            <li>Là cấu trúc dữ liệu có thứ tự (ordered)</li>54                            <li>Không thể thay đổi (immutable)</li>55                            <li>Cho phép trùng lặp giá trị</li>56                            <li>Được khai báo bằng dấu ngoặc tròn ()</li>57                        </ul>58                    </div>59                    <div class="p-4 bg-amber-50 rounded">60                        <h3 class="font-medium">Ví dụ:</h3>61                        <pre class="bg-gray-100 p-4 rounded overflow-x-auto"><code># Khởi tạo tuple62t = (1, 3, 5, "Python")63 64# Truy cập phần tử65print(t[2])  # Output: 566 67# Không thể thay đổi giá trị68# t[1] = 10  # Sẽ báo lỗi TypeError</code></pre>69                    </div>70                </div>71            </div>72 73            <div class="bg-white p-6 rounded-lg shadow-md mb-8">74                <h2 class="text-2xl font-semibold text-amber-500 mb-4">3. Tập hợp (Set)</h2>75                <div class="space-y-4">76                    <div class="p-4 bg-amber-50 rounded">77                        <h3 class="font-medium">Đặc điểm:</h3>78                        <ul class="list-disc pl-5 mt-2">79                            <li>Không có thứ tự (unordered)</li>80                            <li>Có thể thay đổi (mutable)</li>81                            <li>Không cho phép trùng lặp giá trị</li>82                            <li>Được khai báo bằng dấu ngoặc nhọn {}</li>83                        </ul>84                    </div>85                    <div class="p-4 bg-amber-50 rounded">86                        <h3 class="font-medium">Ví dụ:</h3>87                        <pre class="bg-gray-100 p-4 rounded overflow-x-auto"><code># Khởi tạo tập hợp88s = {2, 4, 6, 8}89 90# Thêm phần tử91s.add(10)92print(s)  # Output: {2, 4, 6, 8, 10}93 94# Xóa phần tử95s.remove(4)96print(s)  # Output: {2, 6, 8, 10}</code></pre>97                    </div>98                </div>99            </div>100            <div class="bg-white p-6 rounded-lg shadow-md mb-8">101                <h2 class="text-2xl font-semibold text-amber-500 mb-4">4. Từ điển (Dictionary)</h2>102<div class="space-y-4">103                    <div class="p-4 bg-amber-50 rounded">104                        <h3 class="font-medium">Đặc điểm:</h3>105                        <ul class="list-disc pl-5 mt-2">106                            <li>Lưu trữ dữ liệu dạng key-value</li>107                            <li>Không có thứ tự (unordered)</li>108                            <li>Có thể thay đổi (mutable)</li>109                            <li>Key phải là duy nhất</li>110                            <li>Được khai báo bằng dấu ngoặc nhọn {key: value}</li>111                        </ul>112                    </div>113                    <div class="p-4 bg-amber-50 rounded">114                        <h3 class="font-medium">Ví dụ:</h3>115                        <pre class="bg-gray-100 p-4 rounded overflow-x-auto"><code># Khởi tạo từ điển116td = {117    "tên": "Nguyễn Văn A",118    "tuổi": 25,119    "nghề": "lập trình viên"120}121 122# Truy cập giá trị123print(td["tuổi"])  # Output: 25124 125# Thêm/Thay đổi giá trị126td["lương"] = 20000000127td["tuổi"] = 26128print(td)  # Output: {'tên': 'Nguyễn Văn A', 'tuổi': 26, 'nghề': 'lập trình viên', 'lương': 20000000}</code></pre>129                    </div>130                </div>131            </div>132 133            <div class="bg-white p-6 rounded-lg shadow-md">134                <h2 class="text-2xl font-semibold text-amber-500 mb-4">5. Câu Lệnh Điều Kiện</h2>135                <div class="space-y-4">136                    <div class="p-4 bg-amber-50 rounded">137                        <h3 class="font-medium">Cú pháp cơ bản:</h3>138                        <ul class="list-disc pl-5 mt-2">139                            <li><code>if</code>: Kiểm tra điều kiện đầu tiên</li>140                            <li><code>elif</code>: Kiểm tra các điều kiện tiếp theo (có thể có nhiều hoặc không có)</li>141                            <li><code>else</code>: Thực thi khi tất cả điều kiện trên sai (không bắt buộc)</li>142                        </ul>143                    </div>144                    <div class="p-4 bg-amber-50 rounded">145                        <h3 class="font-medium">Toán tử so sánh:</h3>146                        <ul class="list-disc pl-5 mt-2">147                            <li><code>==</code>: Bằng</li>148                            <li><code>!=</code>: Khác</li>149                            <li><code>&gt;</code>: Lớn hơn</li>150                            <li><code>&lt;</code>: Nhỏ hơn</li>151                            <li><code>&gt;=</code>: Lớn hơn hoặc bằng</li>152                            <li><code>&lt;=</code>: Nhỏ hơn hoặc bằng</li>153                        </ul>154                    </div>155                    <div class="p-4 bg-amber-50 rounded">156                        <h3 class="font-medium">Toán tử logic:</h3>157                        <ul class="list-disc pl-5 mt-2">158                            <li><code>and</code>: Và (cả hai điều kiện đúng)</li>159                            <li><code>or</code>: Hoặc (một trong hai điều kiện đúng)</li>160                            <li><code>not</code>: Phủ định</li>161                        </ul>162                    </div>163                    <div class="p-4 bg-amber-50 rounded">164                        <h3 class="font-medium">Ví dụ:</h3>165                        <pre class="bg-gray-100 p-4 rounded overflow-x-auto"><code># Ví dụ cơ bản166tuoi = 18167if tuoi < 18:168    print("Bạn chưa đủ tuổi")169elif tuoi == 18:170    print("Bạn vừa đủ tuổi")171else:172    print("Bạn đã đủ tuổi")173 174# Ví dụ với toán tử logic175diem = 8.5176if diem >= 8.0 and diem <= 10:177    print("Học sinh giỏi")178elif diem >= 6.5 or diem == 5.0:179    print("Học sinh khá hoặc đặc biệt")180else:181    print("Học sinh trung bình")182 183# Câu lệnh if lồng nhau184so = 10185if so > 0:186    if so % 2 == 0:187        print("Số dương chẵn")188    else:189        print("Số dương lẻ")190else:191    print("Số không dương")</code></pre>192                    </div>193                </div>194            </div>195        </section>196    </main>197<custom-footer></custom-footer>198 199    <script src="components/navbar.js"></script>200    <script src="components/footer.js"></script>201    <script src="script.js"></script>202    <script>feather.replace();</script>203</body>204</html>