<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:media="http://search.yahoo.com/mrss/" >

<channel>
	<title>kiểu dữ liệu &#8211; AnonyViet</title>
	<atom:link href="https://anonyviet.com/tag/kieu-du-lieu/feed/" rel="self" type="application/rss+xml" />
	<link>https://anonyviet.com</link>
	<description>Webiste chia sẻ kiến thức công nghệ thông tin, mạng máy tính, bảo mật phổ biến nhất Việt Nam. Luôn cập nhật tin tức, thủ thuật nóng hổi nhất</description>
	<lastBuildDate>Thu, 24 Jul 2025 12:38:23 +0000</lastBuildDate>
	<language>vi</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://anonyviet.com/wp-content/uploads/2018/10/cropped-ico-logo-75x75.png</url>
	<title>kiểu dữ liệu &#8211; AnonyViet</title>
	<link>https://anonyviet.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Các kiểu dữ liệu cơ bản trong Python</title>
		<link>https://anonyviet.com/cac-kieu-du-lieu-co-ban-trong-python/</link>
					<comments>https://anonyviet.com/cac-kieu-du-lieu-co-ban-trong-python/#respond</comments>
		
		<dc:creator><![CDATA[Ellyx13]]></dc:creator>
		<pubDate>Tue, 12 Jan 2021 04:10:39 +0000</pubDate>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[kiểu dữ liệu]]></category>
		<category><![CDATA[lập trình]]></category>
		<category><![CDATA[python]]></category>
		<guid isPermaLink="false">https://anonyviet.com/?p=24406</guid>

					<description><![CDATA[Kiểu dữ liệu là một trong những thành phần quan trọng nhất của python. Bạn có thể làm rất nhiều thứ thú vị với các kiểu dữ liệu này. Có một sự thật là trong python, tất cả các kiểu dữ liệu đều là dạng đối tượng (object) cả. Kiểu dữ liệu giống như một [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><strong>Kiểu dữ liệu là một trong những thành phần quan trọng nhất của <a href="https://anonyviet.com/tag/python/">python</a>. Bạn có thể làm rất nhiều thứ thú vị với các kiểu dữ liệu này. Có một sự thật là trong python, tất cả các kiểu dữ liệu đều là dạng đối tượng (object) cả.</strong></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter  size-full" src="https://anonyviet.com/wp-content/uploads/2021/01/70.jpeg" alt="Kiểu dữ liệu python" width="607" height="376" title="Các kiểu dữ liệu cơ bản trong Python 17"></p>
<p>Kiểu dữ liệu giống như một đặc điểm về loại dữ liệu mình muốn lưu trữ trong bộ nhớ và python có một số kiểu dữ liệu tích hợp sau:</p>
<ul>
<li>Kiểu văn bản chuỗi: str</li>
<li>Kiểu số: int, float, complex</li>
<li>Các loại trình tự: list, tuple, range</li>
<li>Kiểu ánh xạ: dict</li>
<li>Kiểu dữ liệu set: set, frozenset</li>
<li>Kiểu boolean: bool</li>
<li>Kiểu nhị phân: byte, bytearray, memoryview</li>
</ul>
<p>Bây giờ, hãy phân loại tất cả các kiểu dữ liệu này bằng cách sử dụng hàm <code>type()</code> để hiển thị kiểu dữ liệu của biến.</p>
<h2>Dạng văn bản</h2>
<h3>Kiểu dữ liệu chuỗi str</h3>
<p>str là viết tắt của string (chuỗi) được sử dụng để lưu trữ văn bản trong python. Chuỗi có thể được viết trong dấu nháy kép hoặc dấu nháy đơn, do đó bạn có thể viết như sau:</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="aligncenter  size-full" src="https://anonyviet.com/wp-content/uploads/2021/01/71.png" alt="Kiểu dữ liệu chuỗi str python" width="923" height="387" title="Các kiểu dữ liệu cơ bản trong Python 18"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">Hello, world!
&lt;class 'str'&gt;</pre>
<h2>Kiểu số</h2>
<h3>Kiểu dữ liệu số nguyên int</h3>
<p>int là viết tắt của integer (số nguyên) được sử dụng để lưu trữ số nguyên (số nguyên dương và số nguyên âm).</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="aligncenter  size-full" src="https://anonyviet.com/wp-content/uploads/2021/01/72.jpeg" alt="Kiểu dữ liệu số nguyên int python" width="572" height="194" title="Các kiểu dữ liệu cơ bản trong Python 19"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">4
&lt;class 'int'&gt;</pre>
<h3>Kiểu dữ liệu số thực float</h3>
<p>float là viết tắt của số thực (số thập phân).</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="aligncenter  size-full" src="https://anonyviet.com/wp-content/uploads/2021/01/73.png" alt="Kiểu dữ liệu số thực float python" width="923" height="387" title="Các kiểu dữ liệu cơ bản trong Python 20"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">3.14
&lt;class 'float'&gt;</pre>
<p>Số phức có phần thực và phần ảo, mỗi phần là một số thực. Số phức có thể được viết dưới hai dạng: real + (imag)jcomplex(real, imag).</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/74.png" alt="Các kiểu dữ liệu cơ bản trong Python 13" width="923" height="387" data-wp-editing="1" title="Các kiểu dữ liệu cơ bản trong Python 21"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic"><code>(5+10j)
&lt;class 'complex'&gt;</code></pre>
<h2>Kiểu dữ liệu loại trình tự</h2>
<h3>list</h3>
<p>List (danh sách) là kiểu dữ liệu nơi bạn có thể lưu trữ một tập hợp dữ liệu. List cũng có thể chứa các kiểu dữ liệu khác nhau. List còn có thể sắp xếp, thay đổi phần tử và cho phép các phần tử xuất hiện trùng lặp</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/75.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 14" width="649" height="207" title="Các kiểu dữ liệu cơ bản trong Python 22"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye']
&lt;class 'list'&gt;</pre>
<h3>tuple</h3>
<p>Tuple là kiểu dữ liệu nơi bạn có thể lưu trữ một bộ sưu tập dữ liệu. Tuple cũng có thể chứa các kiểu dữ liệu khác nhau. Tuple có thể sắp xếp, không thể thay đổi các phần tử và cho phép các phần tử được trùng lặp.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/76-1.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 15" width="649" height="194" title="Các kiểu dữ liệu cơ bản trong Python 23"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">('Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye')
&lt;class 'tuple'&gt;</pre>
<h3>range</h3>
<p>Kiểu range đại diện cho một chuỗi số bất biến (không thể thay đổi). Thường được sử dụng để lặp lại một số lần cụ thể trong vòng lặp for.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/77.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 16" width="1005" height="387" title="Các kiểu dữ liệu cơ bản trong Python 24"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">range(0, 10)
&lt;class 'range'&gt;</pre>
<h2>Kiểu dữ liệu ánh xạ</h2>
<h3>dict</h3>
<p>dict là viết tắt của dictionary trong python. Dict được sử dụng để lưu trữ các giá trị dữ liệu trong các key:value. Dict là một tập hợp không có thứ tự, có thể thay đổi và không cho phép trùng lặp.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/78.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 17" width="572" height="194" title="Các kiểu dữ liệu cơ bản trong Python 25">Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">{'Learning': 'Programming', 'Language': 'Python', 'Day': 4}
&lt;class 'dict'&gt;</pre>
<h2>Kiểu dữ liệu Set</h2>
<h3>set</h3>
<p>set là kiểu dữ liệu nơi bạn có thể chứa một tập hợp dữ liệu. Set cũng có thể chứa các kiểu dữ liệu khác nhau. Set không có thứ tự và không được lập chỉ mục và không cho phép các phần tử trùng lặp.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/79.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 18" width="649" height="194" title="Các kiểu dữ liệu cơ bản trong Python 26"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">{'Black Widow', 'Iron Man', 'Thor', 'Hawkeye', 'Hulk', 'Captain America'}
&lt;class 'set'&gt;</pre>
<h3>frozenset</h3>
<p>Kiểu dữ liệu frozenset có thể được tạo bởi hàm <code>frozenset()</code>. Hàm <code>frozenset()</code> chấp nhận một đối tượng có thể lặp lại và trả về một đối tượng frozenset không thể thay đổi (giống như một set object, chỉ là không thể thay đổi).</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/80.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 19" width="1143" height="387" title="Các kiểu dữ liệu cơ bản trong Python 27"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">frozenset({'cherry', 'banana', 'apple'})
&lt;class 'frozenset'&gt;</pre>
<h2>Kiểu boolean</h2>
<h3>bool</h3>
<p>bool là viết tắt của boolean trong python. Booleans đại diện cho một trong hai giá trị: True hoặc False.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/81.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 20" width="1143" height="468" title="Các kiểu dữ liệu cơ bản trong Python 28"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">True
&lt;class 'bool'&gt;
False
&lt;class 'bool'&gt;</pre>
<h2>Kiểu nhị phân</h2>
<h3>bytes</h3>
<p>kiểu dữ liệu byte có thể được tạo ở hai dạng: dùng hàm byte() hoặc sử dụng tiền tố &#8220;b&#8221;.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/82.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 21" width="572" height="275" title="Các kiểu dữ liệu cơ bản trong Python 29"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">b'hello'
&lt;class 'bytes'&gt;
b'Hello'
&lt;class 'bytes'&gt;</pre>
<h3>bytearray</h3>
<p>Hàm<code> bytearray()</code> trả về một đối tượng bytearray. Nó có thể chuyển đổi các đối tượng thành các đối tượng bytearray.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/83.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 22" width="572" height="194" title="Các kiểu dữ liệu cơ bản trong Python 30"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">bytearray(b'\x00\x00\x00\x00')
&lt;class 'bytearray'&gt;</pre>
<h3>memoryview</h3>
<div class="TnITTtw-tpart TnITTtw-t">hàm <code>memoryview()</code> trả về một đối tượng ở chế độ xem bộ nhớ của một đối tượng được chỉ định.</div>
<div>Ví dụ:</div>
<div><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/84.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 23" width="572" height="207" title="Các kiểu dữ liệu cơ bản trong Python 31"></div>
<div>Kết quả:</div>
<div>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">&lt;memory at 0x2b4f7a8a7408&gt;
&lt;class 'memoryview'&gt;</pre>
<p><span style="color: #1d1f20; font-size: 1.953em;">Ghi chú</span></p>
</div>
<div>
<p>Như bạn đã thấy, một số kiểu dữ liệu cũng có thể được triển khai bằng cách sử dụng các constructors của chúng. Kỹ thuật tương tự này cũng có thể được áp dụng cho mọi kiểu dữ liệu.</p>
<p>Ví dụ:</p>
<p><img decoding="async" class="size-full  aligncenter" src="https://anonyviet.com/wp-content/uploads/2021/01/85.jpeg" alt="Các kiểu dữ liệu cơ bản trong Python 24" width="1434" height="1440" title="Các kiểu dữ liệu cơ bản trong Python 32"></p>
<p>Kết quả:</p>
<pre class="EnlighterJSRAW" data-enlighter-language="generic">Hello, World!
4
3.14
(5+10j)
['Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye']
('Captain America', 'Iron Man', 'Thor', 'Hulk', 'Black Widow', 'Hawkeye')
range(0, 10)
{'Learning': 'Programming', 'Language': 'Python', 'Day': 4}
{'apple', 'cherry', 'banana'}
frozenset({'banana', 'cherry', 'apple'})
True
False
b'\x00\x00\x00\x00'
bytearray(b'\x00\x00\x00\x00')
&lt;memory at 0x2b8346a29408&gt;</pre>
<p>Nếu các bạn ủng hộ và mình thấy view bài này cao thì mình sẽ làm thêm vài bài so sánh các kiểu dữ liệu trong python nữa. Vậy nên ủng hộ mình nhé.</p>
</div>
<h2>Câu hỏi thường gặp</h2>
<h3>Python có bao nhiêu kiểu dữ liệu cơ bản?</h3>
<p>Python cung cấp nhiều kiểu dữ liệu cơ bản, bao gồm kiểu số (int, float, complex), kiểu chuỗi (str), kiểu trình tự (list, tuple, range), kiểu ánh xạ (dict), kiểu tập hợp (set, frozenset), kiểu Boolean (bool) và kiểu nhị phân (bytes, bytearray, memoryview).</p>
<h3>Làm thế nào để xác định kiểu dữ liệu của một biến trong Python?</h3>
<p>Sử dụng hàm <code>type()</code>. Ví dụ: <code>type(my_variable)</code> sẽ trả về kiểu dữ liệu của biến <code>my_variable</code>.</p>
<h3>Sự khác biệt giữa list và tuple trong Python là gì?</h3>
<p>Cả list và tuple đều là kiểu dữ liệu trình tự, nhưng list là có thể thay đổi (mutable) còn tuple là không thể thay đổi (immutable). Điều này có nghĩa là bạn có thể thêm, xóa hoặc sửa đổi các phần tử trong list, nhưng không thể làm điều đó với tuple.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://anonyviet.com/cac-kieu-du-lieu-co-ban-trong-python/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
