<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python :: My Site</title><link>https://trungnte.github.io/my-fcj-blog/python/index.html</link><description>Some NOTE when I am learning Python
01-Lists 02-Tuples 03-Dictionaries 04-Sets</description><generator>Hugo</generator><language>en</language><lastBuildDate>Thu, 07 May 2026 18:30:25 +0700</lastBuildDate><atom:link href="https://trungnte.github.io/my-fcj-blog/python/index.xml" rel="self" type="application/rss+xml"/><item><title>01-Lists</title><link>https://trungnte.github.io/my-fcj-blog/python/01-lists/index.html</link><pubDate>Tue, 05 May 2026 14:27:38 +0700</pubDate><guid>https://trungnte.github.io/my-fcj-blog/python/01-lists/index.html</guid><description>Một số chú ý về Lists trong Python 1. List có phải là array không? Trước đây mình hay cho rằng list trong Python chính là array, nhưng thực ra không phải như vậy. Các phần tử trong list có kiểu dữ liệu data type có thể không giống nhau. Shell &gt;&gt;&gt; a = [3.2, 'hello', [4, 7, 17.1]] &gt;&gt;&gt; print(a) [3.2, 'hello', [4, 7, 17.1]] &gt;&gt;&gt; type(a) &lt;class 'list'&gt; &gt;&gt;&gt; 2. Copy một list Shell &gt;&gt;&gt; a = [1, 2, 3] &gt;&gt;&gt; b = a &gt;&gt;&gt; print(a, b) [1, 2, 3] [1, 2, 3] &gt;&gt;&gt; b.sort(reverse = True) &gt;&gt;&gt; print(a, b) [3, 2, 1] [3, 2, 1] &gt;&gt;&gt; Thật thú vị, gán biến b = a, thì Python không clone data ra mà trỏ luôn vùng nhớ của a cho b. Sau khi search google thì mình mới biết đến shallow copy và deep copy 2.1 Shallow copy Shell &gt;&gt;&gt; a = [1, 2, 3] &gt;&gt;&gt; b = a.copy() &gt;&gt;&gt; print(a, b) [1, 2, 3] [1, 2, 3] &gt;&gt;&gt; b.sort(reverse = True) &gt;&gt;&gt; print(a, b) [1, 2, 3] [3, 2, 1] &gt;&gt;&gt; Important Chỉ đơn giản là dùng hàm copy để clone data Cách khác là dùng slicing để copy data Shell &gt;&gt;&gt; c = a[0:1] &gt;&gt;&gt; print(a, c) [1, 2, 3] [1] &gt;&gt;&gt; a.sort(reverse = True) &gt;&gt;&gt; print(a, c) [3, 2, 1] [1] &gt;&gt;&gt; 2.2 Deep copy Important Dùng cho nested lists để chắc chắc rằng tất cả các phần tử trong các đối tượng bên trong list đều được copy và độc lập</description></item><item><title>02-Tuples</title><link>https://trungnte.github.io/my-fcj-blog/python/02-tuples/index.html</link><pubDate>Thu, 07 May 2026 11:57:24 +0700</pubDate><guid>https://trungnte.github.io/my-fcj-blog/python/02-tuples/index.html</guid><description>1. Overview Important A Tuple is rather similar to a list, but is defined using round brackets, (). Tuples can contain multiple elements, and the elements may not share the same type. The key difference is that tuples are immutable, so that once a tuple is created it cannot subsequently be changed. (It can be extended - but this is effectively the creation of a new, larger tuple!). As a lists, the indivisual elements of a tuple can be accessed using [index] after the tuple name. Shell &gt;&gt;&gt; a = (1, 2, 3, 'x', (1, 2, 3), [5, 6, 7]) &gt;&gt;&gt; print(a) (1, 2, 3, 'x', (1, 2, 3), [5, 6, 7]) &gt;&gt;&gt; type(a) &lt;class 'tuple'&gt; &gt;&gt;&gt; 2. Convert to list and vice versa Note A tuple can be converted into a list and vice versa</description></item><item><title>03-Dictionaries</title><link>https://trungnte.github.io/my-fcj-blog/python/03-dictionaries/index.html</link><pubDate>Thu, 07 May 2026 18:29:22 +0700</pubDate><guid>https://trungnte.github.io/my-fcj-blog/python/03-dictionaries/index.html</guid><description>1. Overview Dictionaries provide a mechanism for storing data labelled with a keyword or other information. Use curly brackets to create a dictionary, and associate each piece of data with a label. Shell &gt;&gt;&gt; a = {'mass': 17.3, 'length': 0.7} &gt;&gt;&gt; print(a) {'mass': 17.3, 'length': 0.7} &gt;&gt;&gt; type(a) &lt;class 'dict'&gt; Or another syntax
Shell &gt;&gt;&gt; b = dict(name='Trung', age=38) &gt;&gt;&gt; print(b) {'name': 'Trung', 'age': 38} &gt;&gt;&gt; type(b) &lt;class 'dict'&gt; 2. Some methods particular to dictionaries a.keys()</description></item><item><title>04 Sets</title><link>https://trungnte.github.io/my-fcj-blog/python/04-sets/index.html</link><pubDate>Thu, 07 May 2026 18:30:25 +0700</pubDate><guid>https://trungnte.github.io/my-fcj-blog/python/04-sets/index.html</guid><description>1. Overview Set: is an unordered collection of unique objects. A set can be created from a tuple or list Shell &gt;&gt;&gt; a = [3, 4, 5] &gt;&gt;&gt; s = set(a) &gt;&gt;&gt; print(s) {3, 4, 5} &gt;&gt;&gt; type(s) &lt;class 'set'&gt; 2. Some notes 2.1 Duplicates Important Duplicates are ignored
Shell &gt;&gt;&gt; a = [3, 4, 5] &gt;&gt;&gt; s = set(a) &gt;&gt;&gt; print(s) {3, 4, 5} &gt;&gt;&gt; type(s) &lt;class 'set'&gt; &gt;&gt;&gt; &gt;&gt;&gt; a = [3, 3, 5] &gt;&gt;&gt; s = set(a) &gt;&gt;&gt; print(s) {3, 5} &gt;&gt;&gt; 2.2 The | operator and the &amp; operator Shell &gt;&gt;&gt; a = set([3, 4, 5]) &gt;&gt;&gt; b = set([4, 5, 6]) &gt;&gt;&gt; print(a) {3, 4, 5} &gt;&gt;&gt; print(b) {4, 5, 6} &gt;&gt;&gt; print(a | b) {3, 4, 5, 6} &gt;&gt;&gt; print(a &amp; b) {4, 5} &gt;&gt;&gt; 2.3 The - operator and the ^ operator Shell &gt;&gt;&gt; print(a) {3, 4, 5} &gt;&gt;&gt; print(b) {4, 5, 6} &gt;&gt;&gt; print(b - a) {6} &gt;&gt;&gt; print(b ^ a) {3, 6} &gt;&gt;&gt;</description></item></channel></rss>