<!DOCTYPE html>
    <html lang="vi" xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
    <head>
<title>Hàm list&#40;&#41; trong Python</title>
<meta name="description" content="Hàm list&#40;&#41; trong Python - Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;www.nguoicodonvn2008.info&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;kien-thuc-may-tinh&#x002F;ham-list-trong-python-9942.html">
<meta name="author" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :.">
<meta name="copyright" content=".: Nguoicodonvn2008.info - Cõi lòng người cô đơn :. [admin@nguoicodonvn2008.info]">
<meta name="robots" content="index, archive, follow, noodp">
<meta name="googlebot" content="index,archive,follow,noodp">
<meta name="msnbot" content="all,index,follow">
<meta name="generator" content="NukeViet v4.5">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta property="og:title" content="Hàm list&#40;&#41; trong Python">
<meta property="og:type" content="website">
<meta property="og:description" content="Savefile - Tin Tức - https&#x3A;&#x002F;&#x002F;www.nguoicodonvn2008.info&#x002F;vi&#x002F;news&#x002F;savefile&#x002F;kien-thuc-may-tinh&#x002F;ham-list-trong-python-9942.html">
<meta property="og:site_name" content=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.">
<meta property="og:url" content="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/ham-list-trong-python-9942.html">
<link rel="shortcut icon" href="https://nguoicodonvn2008.info/favicon.ico">
<link rel="canonical" href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/ham-list-trong-python-9942.html">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/" title="Tin Tức" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/karaoke-dual/" title="Tin Tức - Karaoke Dual" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/nhac-tre/" title="Tin Tức - Nhạc trẻ" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tru-tinh/" title="Tin Tức - Trữ tình" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/nuoc-ngoai/" title="Tin Tức - Nước ngoài" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/remix/" title="Tin Tức - Remix" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tam-su-tinh-yeu/" title="Tin Tức - Tâm sự tình yêu" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tho-suu-tam/" title="Tin Tức - Thơ sưu tầm" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/cuoc-song/" title="Tin Tức - Cuộc sống" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/phan-mem/" title="Tin Tức - Phần mềm" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/kien-thuc-may-tinh/" title="Tin Tức - Kiến thức máy tính" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/hoc-tap/" title="Tin Tức - Học tập" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/tai-lieu/" title="Tin Tức - Tài liệu" type="application/rss+xml">
<link rel="alternate" href="https://nguoicodonvn2008.info/vi/news/rss/de-thi/" title="Tin Tức - Đề thi" type="application/rss+xml">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/assets/css/font-awesome.min.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/style.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/style.non-responsive.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/news.css" type="text/css">
<link rel="preload" as="style" href="https://nguoicodonvn2008.info/themes/default/css/custom.css" type="text/css">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/jquery/jquery.min.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/language/vi.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/global.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/assets/js/site.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/news.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/main.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/custom.js" type="text/javascript">
<link rel="preload" as="script" href="https://nguoicodonvn2008.info/themes/default/js/bootstrap.min.js" type="text/javascript">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/assets/css/font-awesome.min.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/bootstrap.non-responsive.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/style.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/style.non-responsive.css">
<link rel="StyleSheet" href="https://nguoicodonvn2008.info/themes/default/css/news.css">
<link rel="stylesheet" href="https://nguoicodonvn2008.info/themes/default/css/custom.css">
<style type="text/css">
	body{background: #fff;}
</style>
    </head>
    <body>
<div id="print">
	<div id="hd_print">
		<h2 class="pull-left">.&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.</h2>
		<p class="pull-right"><a title=".&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;." href="https://nguoicodonvn2008.info/">https://nguoicodonvn2008.info</a></p>
	</div>
	<div class="clear"></div>
	<hr />
	<div id="content">
		<h1>Hàm list&#40;&#41; trong Python</h1>
		<ul class="list-inline">
			<li>Thứ năm - 06/03/2025 21:52</li>
			<li class="hidden-print txtrequired"><em class="fa fa-print">&nbsp;</em><a title="In ra" href="javascript:;" onclick="window.print()">In ra</a></li>
			<li class="hidden-print txtrequired"><em class="fa fa-power-off">&nbsp;</em><a title="Đóng cửa sổ này" href="javascript:;" onclick="window.close()">Đóng cửa sổ này</a></li>
		</ul>
		<div class="clear"></div>
		<div id="hometext">
		</div>
				<div class="imghome">
			<img alt="Hàm list&#40;&#41; trong Python" src="https://st.quantrimang.com/photos/image/2018/10/16/mang-trong-Python-200-size-80x80-znd.jpg" width="460" class="img-thumbnail" />
		</div>
		<div class="clear"></div>
		<div id="bodytext" class="clearfix">
			<p><strong>Hàm list trong Python</strong>&nbsp;được sử dụng như thế nào? Hãy cùng nhau tìm hiểu cách dùng<strong>&nbsp;lệnh list trong Python</strong>&nbsp;nhé!</p>

<p>Toán tử Python là công cụ thiết yếu cho phép bạn làm việc với các biến và giá trị theo nhiều cách khác nhau. Mã hóa hiệu quả đòi hỏi phải hiểu các toán tử, cho dù bạn đang làm việc với văn bản, số hay cấu trúc dữ liệu như danh sách - list trong Python. Mọi thứ bạn cần biết về bitwise, phép gán, số học, so sánh, logic và toán tử đặc biệt trong Python đều được đề cập ở bài viết này. Cuối cùng, bạn sẽ hiểu rõ cách áp dụng các toán tử này để cải thiện khả năng lập trình Python của mình.</p>

<p>Hiểu đơn giản, list là một tập hợp các mục có thể được quản lý và lưu trữ theo trình tự. Vì danh sách có thể chứa các thành phần của một số kiểu dữ liệu—số nguyên, văn bản và thậm chí cả các danh sách khác—nên chúng cực kỳ linh hoạt cho nhiều ứng dụng máy tính khác nhau. Bạn có thể nhanh chóng thêm, xóa và thay đổi các phần tử khỏi danh sách Python và thực hiện các thao tác như sắp xếp và cắt lát.</p>

<p>Bạn có thể tìm hiểu kỹ hơn về&nbsp;kiểu Tuple, Set và Dictionary&nbsp;trên Quantrimang.com. Chúng có chất lượng và cách sử dụng khác nhau.</p>

<p>Ví dụ List được tạo bằng dấu ngoặc vuông:</p>

<pre id="pre0">
thislist = &#91;&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;&#93;
print(thislist)</pre>

<h2>Cú pháp hàm list() trong Python</h2>

<pre id="pre1">
list(&#91;iterable&#93;)</pre>

<h2>Tham số của hàm list()</h2>

<p>Hàm tạo danh sách list() trong Python có một tham số duy nhất:</p>

<ul>
	<li><em>iterable</em>&nbsp;(không bắt buộc): đối tượng có thể là string, tuple, set, dictionary hoặc đối tượng lặp iterator</li>
</ul>

<h2>Giá trị trả về từ list</h2>

<ul>
	<li>Nếu không truyền tham số, list() sẽ tạo ra một danh sách trống</li>
	<li>Nếu iterable được truyền dưới dạng tham số, nó sẽ tạo một danh sách các phần tử trong iterable</li>
</ul>

<h3>Liệt kê các mục</h3>

<ul>
	<li>Liệt kê các mục theo thứ tự, có thể thay đổi và cho phép trùng lặp giá trị.</li>
	<li>Các mục trong danh sách được đánh chỉ mục. Mục đầu tiên có index &#91;0&#93;, mục thứ hai có index &#91;1&#93;….</li>
</ul>

<h3>Sắp xếp theo thứ tự</h3>

<p>Khi list được “ordered”, điều đó có nghĩa những mục đó đã có thứ tự được xác định và sẽ không thay đổi.</p>

<p>Nếu bạn thêm các mục mới vào danh sách, mục mới đó sẽ được đặt ở cuối cùng.</p>

<p>Lưu ý: Một số phương pháp liệt kê sẽ thay đổi thứ tự này, nhưng nhìn cung; thứ tự của các mục sẽ không thay đổi.</p>

<h2>Ví dụ 1: Tạo danh sách từ string, tuple, list</h2>

<pre id="pre2">
# danh sách trốngprint(list())# chuỗi nguyên âmnguyenamString = &#039;aeiou&#039;print(list(nguyenamString))# tuple nguyên âm# viết bởi Quantrimang.comnguyenamTuple = (&#039;a&#039;, &#039;e&#039;, &#039;i&#039;, &#039;o&#039;, &#039;u&#039;)print(list(nguyenamTuple))# danh sách nguyên âmnguyenamList = &#91;&#039;a&#039;, &#039;e&#039;, &#039;i&#039;, &#039;o&#039;, &#039;u&#039;&#93;print(list(nguyenamList))</pre>

<p>Chạy chương trình, kết quả trả về là:</p>

<pre id="pre3">
&#91;&#93;&#91;&#039;a&#039;, &#039;e&#039;, &#039;i&#039;, &#039;o&#039;, &#039;u&#039;&#93;&#91;&#039;a&#039;, &#039;e&#039;, &#039;i&#039;, &#039;o&#039;, &#039;u&#039;&#93;&#91;&#039;a&#039;, &#039;e&#039;, &#039;i&#039;, &#039;o&#039;, &#039;u&#039;&#93;</pre>

<h2>Ví dụ 2: Tạo danh sách từ set, dictionary</h2>

<pre id="pre4">
# set nguyên âmnguyenamSet = {&#039;a&#039;, &#039;e&#039;, &#039;i&#039;, &#039;o&#039;, &#039;u&#039;}print(list(nguyenamSet))# dictionary nguyên âmnguyenamDictionary = {&#039;a&#039;: 1, &#039;e&#039;: 2, &#039;i&#039;: 3, &#039;o&#039;:4, &#039;u&#039;:5}print(list(nguyenamDictionary))</pre>

<p>Chạy chương trình ta được kết quả là:</p>

<pre id="pre5">
&#91;&#039;e&#039;, &#039;o&#039;, &#039;a&#039;, &#039;i&#039;, &#039;u&#039;&#93;&#91;&#039;e&#039;, &#039;o&#039;, &#039;u&#039;, &#039;a&#039;, &#039;i&#039;&#93;</pre>

<h2>Ví dụ 3: Tạo danh sách từ đối tượng iterator</h2>

<pre id="pre6">
class PowTwo: def __init__(self, max): self.max = max def __iter__(self): self.num = 0 return self def __next__(self): if(self.num &gt;= self.max): raise StopIteration result = 2 ** self.num self.num += 1 return resultpowTwo = PowTwo(5)powTwoIter = iter(powTwo)print(list(powTwoIter))</pre>

<p>Chạy chương trình ta được kết quả là:</p>

<pre id="pre7">
&#91;1, 2, 4, 8, 16&#93;</pre>
		</div>
				<div id="author">
						<p>
				<strong>Nguồn tin:</strong>
				Quantrimang.com:
			</p>
		</div>
	</div>
	<div id="footer" class="clearfix">
		<div id="url">
			<strong>URL của bản tin này: </strong><a href="https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/ham-list-trong-python-9942.html" title="Hàm list&#40;&#41; trong Python">https://www.nguoicodonvn2008.info/vi/news/savefile/kien-thuc-may-tinh/ham-list-trong-python-9942.html</a>

		</div>
		<div class="clear"></div>
		<div class="copyright">
			&copy; .&#x3A; Nguoicodonvn2008.info - Cõi lòng người cô đơn &#x3A;.
		</div>
		<div id="contact">
			<a href="mailto:admin@nguoicodonvn2008.info">admin@nguoicodonvn2008.info</a>
		</div>
	</div>
</div>
        <div id="timeoutsess" class="chromeframe">
            Bạn đã không sử dụng Site, <a onclick="timeoutsesscancel();" href="https://nguoicodonvn2008.info/#">Bấm vào đây để duy trì trạng thái đăng nhập</a>. Thời gian chờ: <span id="secField"> 60 </span> giây
        </div>
        <div id="openidResult" class="nv-alert" style="display:none"></div>
        <div id="openidBt" data-result="" data-redirect=""></div>
		</script>
		<div class="car-top">
  <span><img src="https://nguoicodonvn2008.info/themes/default/images/car.png" alt=""></span>
</div>
<script src="https://nguoicodonvn2008.info/assets/js/jquery/jquery.min.js"></script>
<script>var nv_base_siteurl="/",nv_lang_data="vi",nv_lang_interface="vi",nv_name_variable="nv",nv_fc_variable="op",nv_lang_variable="language",nv_module_name="news",nv_func_name="savefile",nv_is_user=0, nv_my_ofs=-4,nv_my_abbr="EDT",nv_cookie_prefix="nv4c_e856T",nv_check_pass_mstime=1738000,nv_area_admin=0,nv_safemode=0,theme_responsive=0,nv_recaptcha_ver=2,nv_recaptcha_sitekey="",nv_recaptcha_type="image",XSSsanitize=1;</script>
<script src="https://nguoicodonvn2008.info/assets/js/language/vi.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/DOMPurify/purify3.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/global.js"></script>
<script src="https://nguoicodonvn2008.info/assets/js/site.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/news.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/main.js"></script>
<script src="https://nguoicodonvn2008.info/themes/default/js/custom.js"></script>
<script type="application/ld+json">
        {
            "@context": "https://schema.org",
            "@type": "Organization",
            "url": "https://nguoicodonvn2008.info",
            "logo": "https://nguoicodonvn2008.info/uploads/angel.gif"
        }
        </script>
<script src="https://nguoicodonvn2008.info/themes/default/js/bootstrap.min.js"></script>
<script type="text/javascript">
var $scrolltop = $('.car-top');
$scrolltop.on('click', function () {
    $('html,body').animate({
        scrollTop: 0
    }, 800);
    $(this).addClass("car-run");
    setTimeout(function(){ $scrolltop.removeClass('car-run');}, 1000);
    return false;
});
$(window).on('scroll', function ()
{ 
    if($(window).scrollTop() >= 200)
    {
        $scrolltop.addClass("show");
        $scrolltop.addClass("car-down");
    }
    else
    {
       $scrolltop.removeClass("show");
       setTimeout(function(){ $scrolltop.removeClass('car-down');}, 300);
    }
});
</script>
</body>
</html>