{"id":84505,"date":"2025-02-22T23:27:04","date_gmt":"2025-02-22T16:27:04","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=84505"},"modified":"2025-02-22T23:27:04","modified_gmt":"2025-02-22T16:27:04","slug":"cac-lenh-trong-python","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/","title":{"rendered":"C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#Cac_lenh_trong_Python_giup_viet_code_ngan_hon\" >C\u00e1c l\u1ec7nh trong Python gi\u00fap vi\u1ebft code ng\u1eafn h\u01a1n<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#Cac_thu_vien_va_cac_lenh_trong_Python_ho_tro_xu_ly_du_lieu_va_toi_uu\" >C\u00e1c th\u01b0 vi\u1ec7n v\u00e0 c\u00e1c l\u1ec7nh trong Python h\u1ed7 tr\u1ee3 x\u1eed l\u00fd d\u1eef li\u1ec7u v\u00e0 t\u1ed1i \u01b0u<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#Cac_lenh_trong_Python_giup_xu_ly_file_va_quan_ly_tai_nguyen\" >C\u00e1c l\u1ec7nh trong Python gi\u00fap x\u1eed l\u00fd file v\u00e0 qu\u1ea3n l\u00fd t\u00e0i nguy\u00ean<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#Cac_lenh_trong_Python_nang_cao\" >C\u00e1c l\u1ec7nh trong Python n\u00e2ng cao<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#Cau_hoi_thuong_gap_ve_cac_lenh_trong_Python\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 c\u00e1c l\u1ec7nh trong Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#Tong_ket_cac_lenh_trong_Python\" >T\u1ed5ng k\u1ebft c\u00e1c l\u1ec7nh trong Python<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>Ch\u1eafc h\u1eb3n b\u1ea1n \u0111\u00e3 t\u1eebng nghe c\u00e2u n\u00f3i vui \u201cTrong th\u1ebf gi\u1edbi Python, h\u1ea7u nh\u01b0 vi\u1ec7c g\u00ec c\u0169ng c\u00f3 th\u1ec3 gi\u1ea3i quy\u1ebft ch\u1ec9 b\u1eb1ng m\u1ed9t v\u00e0i d\u00f2ng code\u201d. S\u1ef1 th\u1ef1c l\u00e0 Python mang l\u1ea1i r\u1ea5t nhi\u1ec1u l\u1ec7nh \u201ckho b\u00e1u\u201d m\u00e0 n\u1ebfu b\u1ea1n khai th\u00e1c th\u00e0nh th\u1ea1o, t\u1ed1c \u0111\u1ed9 ph\u00e1t tri\u1ec3n d\u1ef1 \u00e1n s\u1ebd nhanh h\u01a1n \u201cm\u1ed9t n\u1ed1t nh\u1ea1c\u201d. Trong b\u00e0i vi\u1ebft n\u00e0y, ch\u00fang ta s\u1ebd c\u00f9ng kh\u00e1m ph\u00e1 h\u00e0ng lo\u1ea1t c\u00e1c l\u1ec7nh trong Python, t\u00ednh n\u0103ng, v\u00e0 c\u00f4ng c\u1ee5 Python\u00a0gi\u00fap b\u1ea1n t\u1ed1i \u01b0u ho\u00e1 d\u1ef1 \u00e1n, \u0111em l\u1ea1i tr\u1ea3i nghi\u1ec7m code t\u1ed1t h\u01a1n.<\/strong><\/em><\/p>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/code-python-co-ban\/\" target=\"_blank\" rel=\"noopener\"><strong>Code Python c\u01a1 b\u1ea3n: H\u01b0\u1edbng d\u1eabn chi ti\u1ebft c\u00e1c l\u1ec7nh Python c\u01a1 b\u1ea3n<\/strong><\/a><\/em><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Cac_lenh_trong_Python_giup_viet_code_ngan_hon\"><\/span><b>C\u00e1c l\u1ec7nh trong Python gi\u00fap vi\u1ebft code ng\u1eafn h\u01a1n<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>enumerate()<\/b><\/h3>\n<p><b>T\u1ea1i sao c\u1ea7n quan t\u00e2m?<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Kh\u00f4ng \u00edt l\u1eadp tr\u00ecnh vi\u00ean m\u1edbi h\u1ecdc Python hay d\u00f9ng c\u00fa ph\u00e1p:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> i <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> range(len(my_list)):<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(i, my_list[i])<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e1ch n\u00e0y ho\u1ea1t \u0111\u1ed9ng t\u1ed1t, nh\u01b0ng h\u01a1i d\u00e0i d\u00f2ng. <\/span><span style=\"font-weight: 400;\">enumerate()<\/span><span style=\"font-weight: 400;\"> gi\u00fap b\u1ea1n l\u1ea5y c\u1ea3 ch\u1ec9 s\u1ed1 (index) v\u00e0 gi\u00e1 tr\u1ecb (value) trong list m\u1ed9t c\u00e1ch s\u1ea1ch s\u1ebd h\u01a1n:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> index, value <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> enumerate(my_list):<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(index, value)<\/span><\/pre>\n<p><b>V\u00ed d\u1ee5 minh h\u1ecda v\u1edbi <\/b><b>my_list<\/b><b>:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">my_list = [<\/span><span style=\"font-weight: 400;\">\"apple\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"banana\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"cherry\"<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n\r\n<span style=\"font-weight: 400;\"># C\u00e1ch 1: D\u00f9ng range(len())<\/span>\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"S\u1eed d\u1ee5ng range(len()):\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> i <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> range(len(my_list)):<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(i, my_list[i])<\/span>\r\n\r\n<span style=\"font-weight: 400;\"># C\u00e1ch 2: D\u00f9ng enumerate()<\/span>\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"\\nS\u1eed d\u1ee5ng enumerate():\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> index, value <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> enumerate(my_list):<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(index, value)<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3 khi ch\u1ea1y m\u00e3 tr\u00ean<\/b><span style=\"font-weight: 400;\">:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng range(len()):<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\"> apple<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\"> banana<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> cherry<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">S\u1eed d\u1ee5ng enumerate():<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\"> apple<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\"> banana<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> cherry<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">D\u00f9 \u0111\u1ea7u ra gi\u1ed1ng nhau, nh\u01b0ng vi\u1ec7c s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">enumerate()<\/span><span style=\"font-weight: 400;\"> gi\u00fap code <\/span><b>ng\u1eafn g\u1ecdn<\/b><span style=\"font-weight: 400;\"> v\u00e0 <\/span><b>r\u00f5 r\u00e0ng<\/b><span style=\"font-weight: 400;\"> h\u01a1n.<\/span><\/p>\n<h3><b>zip()<\/b><\/h3>\n<p><b>T\u1ea1i sao c\u1ea7n quan t\u00e2m?<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Khi b\u1ea1n c\u00f3 hai hay nhi\u1ec1u list, v\u00e0 mu\u1ed1n <\/span><i><span style=\"font-weight: 400;\">gh\u00e9p<\/span><\/i><span style=\"font-weight: 400;\"> c\u00e1c ph\u1ea7n t\u1eed t\u01b0\u01a1ng \u1ee9ng th\u00e0nh t\u1eebng c\u1eb7p (ho\u1eb7c b\u1ed9 nhi\u1ec1u gi\u00e1 tr\u1ecb), <\/span><span style=\"font-weight: 400;\">zip()<\/span><span style=\"font-weight: 400;\"> l\u00e0 v\u1ecb c\u1ee9u tinh. V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">names = [<\/span><span style=\"font-weight: 400;\">\"Alice\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"Bob\"<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">\"Charlie\"<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">scores = [<\/span><span style=\"font-weight: 400;\">90<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">85<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">92<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> name, score <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> zip(names, scores):<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(name, score)<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3:<\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Alice <\/span><span style=\"font-weight: 400;\">90<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">Bob <\/span><span style=\"font-weight: 400;\">85<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">Charlie <\/span><span style=\"font-weight: 400;\">92<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Trong m\u1ed9t <\/span><a href=\"https:\/\/lp.jetbrains.com\/python-developers-survey-2021\/\" target=\"_blank\" rel=\"noopener\"><b>kh\u1ea3o s\u00e1t l\u1eadp tr\u00ecnh<\/b><\/a><span style=\"font-weight: 400;\"> n\u0103m 2021, <\/span><b>60%<\/b><span style=\"font-weight: 400;\"> l\u1eadp tr\u00ecnh vi\u00ean Python cho bi\u1ebft h\u1ecd th\u01b0\u1eddng xuy\u00ean d\u00f9ng <\/span><span style=\"font-weight: 400;\">zip()<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec3 k\u1ebft h\u1ee3p d\u1eef li\u1ec7u, nh\u1ea5t l\u00e0 khi ph\u1ea3i x\u1eed l\u00fd v\u1edbi nhi\u1ec1u t\u1eadp d\u1eef li\u1ec7u song song, nh\u01b0 <\/span><i><span style=\"font-weight: 400;\">list<\/span><\/i><span style=\"font-weight: 400;\"> ch\u1ee9a th\u00f4ng tin sinh vi\u00ean, <\/span><i><span style=\"font-weight: 400;\">list<\/span><\/i><span style=\"font-weight: 400;\"> \u0111i\u1ec3m s\u1ed1, <\/span><i><span style=\"font-weight: 400;\">list<\/span><\/i><span style=\"font-weight: 400;\"> l\u1edbp h\u1ecdc&#8230;<\/span><\/p>\n<h3><b>any()<\/b><b> v\u00e0 <\/b><b>all()<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>any()<\/b><span style=\"font-weight: 400;\"> tr\u1ea3 v\u1ec1 <\/span><span style=\"font-weight: 400;\">True<\/span><span style=\"font-weight: 400;\"> n\u1ebfu <\/span><b>\u00edt nh\u1ea5t m\u1ed9t<\/b><span style=\"font-weight: 400;\"> ph\u1ea7n t\u1eed trong iterable (list, tuple&#8230;) th\u1ecfa \u0111i\u1ec1u ki\u1ec7n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>all()<\/b><span style=\"font-weight: 400;\"> tr\u1ea3 v\u1ec1 <\/span><span style=\"font-weight: 400;\">True<\/span><span style=\"font-weight: 400;\"> n\u1ebfu <\/span><b>t\u1ea5t c\u1ea3<\/b><span style=\"font-weight: 400;\"> ph\u1ea7n t\u1eed trong iterable \u0111\u1ec1u th\u1ecfa \u0111i\u1ec1u ki\u1ec7n.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 nhanh:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">numbers = [<\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">print(any(numbers))\u00a0 <\/span><span style=\"font-weight: 400;\"># True, v\u00ec c\u00f3 gi\u00e1 tr\u1ecb kh\u00e1c 0<\/span>\r\n<span style=\"font-weight: 400;\">print(all(numbers))\u00a0 <\/span><span style=\"font-weight: 400;\"># False, v\u00ec c\u00f3 gi\u00e1 tr\u1ecb b\u1eb1ng 0<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Hay khi k\u1ebft h\u1ee3p v\u1edbi \u0111i\u1ec1u ki\u1ec7n:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">numbers = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">7<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">print(all(n &gt; <\/span><span style=\"font-weight: 400;\">0<\/span> <span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> n <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> numbers))\u00a0 <\/span><span style=\"font-weight: 400;\"># True<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">K\u1ebft qu\u1ea3 in ra s\u1ebd l\u00e0 <\/span><span style=\"font-weight: 400;\">True<\/span><span style=\"font-weight: 400;\"> v\u00ec t\u1ea5t c\u1ea3 c\u00e1c ph\u1ea7n t\u1eed trong danh s\u00e1ch <\/span><span style=\"font-weight: 400;\">[1, 3, 5, 7]<\/span><span style=\"font-weight: 400;\"> \u0111\u1ec1u th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n <\/span><span style=\"font-weight: 400;\">n &gt; 0<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<h3><b>Walrus Operator (<\/b><b>:=<\/b><b>)<\/b><\/h3>\n<p><b>T\u1ea1i sao c\u1ea7n quan t\u00e2m?<\/b><\/p>\n<p><span style=\"font-weight: 400;\">Walrus Operator, hay <\/span><b>To\u00e1n t\u1eed H\u00e0 M\u00e3<\/b><span style=\"font-weight: 400;\">, ch\u00ednh th\u1ee9c ra m\u1eaft trong Python 3.8. N\u00f3 cho ph\u00e9p b\u1ea1n g\u00e1n bi\u1ebfn tr\u1ef1c ti\u1ebfp trong bi\u1ec3u th\u1ee9c, thay v\u00ec ph\u1ea3i t\u00e1ch bi\u1ec7t m\u1ed9t d\u00f2ng g\u00e1n bi\u1ebfn v\u00e0 m\u1ed9t d\u00f2ng if\/while\/v\u00f2ng l\u1eb7p. V\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> (length := len(my_list)) &gt; <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(<\/span><span style=\"font-weight: 400;\">f\"Danh s\u00e1ch n\u00e0y c\u00f3 <\/span><span style=\"font-weight: 400;\">{length}<\/span><span style=\"font-weight: 400;\"> ph\u1ea7n t\u1eed, kh\u00e1 d\u00e0i!\"<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">L\u1ee3i \u00edch l\u00e0 code gi\u1ea3m \u0111\u1ed9 r\u01b0\u1eddm r\u00e0, nh\u01b0ng b\u1ea1n c\u0169ng c\u1ea7n c\u1ea9n tr\u1ecdng tr\u00e1nh l\u1ea1m d\u1ee5ng d\u1eabn \u0111\u1ebfn kh\u00f3 \u0111\u1ecdc. Theo c\u00e1c di\u1ec5n \u0111\u00e0n tr\u00ean Reddit, ch\u01b0a c\u00f3 nhi\u1ec1u c\u00e1c l\u1eadp tr\u00ecnh vi\u00ean Python th\u01b0\u1eddng xuy\u00ean s\u1eed d\u1ee5ng Walrus Operator, v\u00ec nhi\u1ec1u ng\u01b0\u1eddi v\u1eabn \u201cng\u1ea1i\u201d c\u00fa ph\u00e1p m\u1edbi ho\u1eb7c s\u1ee3 g\u00e2y kh\u00f3 hi\u1ec3u cho \u0111\u1ed3ng nghi\u1ec7p.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cac_thu_vien_va_cac_lenh_trong_Python_ho_tro_xu_ly_du_lieu_va_toi_uu\"><\/span><b>C\u00e1c th\u01b0 vi\u1ec7n v\u00e0 c\u00e1c l\u1ec7nh trong Python h\u1ed7 tr\u1ee3 x\u1eed l\u00fd d\u1eef li\u1ec7u v\u00e0 t\u1ed1i \u01b0u<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>collections.Counter<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">H\u1ea7u h\u1ebft l\u1eadp tr\u00ecnh vi\u00ean \u0111\u1ec1u g\u1eb7p t\u00ecnh hu\u1ed1ng ph\u1ea3i \u0111\u1ebfm t\u1ea7n su\u1ea5t xu\u1ea5t hi\u1ec7n c\u1ee7a ph\u1ea7n t\u1eed trong danh s\u00e1ch. Thay v\u00ec d\u00f9ng v\u00f2ng l\u1eb7p ki\u1ec3m tra t\u1eebng gi\u00e1 tr\u1ecb, ta c\u00f3 <\/span><span style=\"font-weight: 400;\">Counter<\/span><span style=\"font-weight: 400;\">:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> collections <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> Counter<\/span>\r\n\r\n<span style=\"font-weight: 400;\">my_list = [<\/span><span style=\"font-weight: 400;\">'apple'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'banana'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'apple'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'orange'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'banana'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'apple'<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">counter = Counter(my_list)<\/span>\r\n<span style=\"font-weight: 400;\">print(counter)<\/span>\r\n<span style=\"font-weight: 400;\"># Counter({'apple': 3, 'banana': 2, 'orange': 1})<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e1c k\u1ef9 s\u01b0 senior th\u01b0\u1eddng xuy\u00ean s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">Counter<\/span><span style=\"font-weight: 400;\"> nh\u01b0 m\u1ed9t ph\u1ea7n c\u1ed1t l\u00f5i \u0111\u1ec3 th\u1ed1ng k\u00ea t\u1ea7n su\u1ea5t khi x\u1eed l\u00fd c\u00e1c chu\u1ed7i, nh\u1eadt k\u00fd (log), ho\u1eb7c d\u1eef li\u1ec7u th\u00f4.<\/span><\/p>\n<h3><b>defaultdict<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u0110\u00e3 bao gi\u1edd b\u1ea1n vi\u1ebft code \u0111\u1ec3 ki\u1ec3m tra xem m\u1ed9t key \u0111\u00e3 t\u1ed3n t\u1ea1i trong dictionary ch\u01b0a, n\u1ebfu kh\u00f4ng t\u1ed3n t\u1ea1i th\u00ec t\u1ea1o m\u1edbi, n\u1ebfu t\u1ed3n t\u1ea1i th\u00ec c\u1eadp nh\u1eadt gi\u00e1 tr\u1ecb? <\/span><span style=\"font-weight: 400;\">defaultdict<\/span><span style=\"font-weight: 400;\"> gi\u00fap b\u1ea1n r\u00fat ng\u1eafn quy tr\u00ecnh \u0111\u00f3:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> collections <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> defaultdict<\/span>\r\n\r\n<span style=\"font-weight: 400;\">my_dict = defaultdict(int)<\/span>\r\n<span style=\"font-weight: 400;\">my_dict[<\/span><span style=\"font-weight: 400;\">'apple'<\/span><span style=\"font-weight: 400;\">] += <\/span><span style=\"font-weight: 400;\">1<\/span>\r\n<span style=\"font-weight: 400;\">my_dict[<\/span><span style=\"font-weight: 400;\">'banana'<\/span><span style=\"font-weight: 400;\">] += <\/span><span style=\"font-weight: 400;\">2<\/span>\r\n<span style=\"font-weight: 400;\">print(my_dict)\u00a0 <\/span><span style=\"font-weight: 400;\"># defaultdict(&lt;class 'int'&gt;, {'apple': 1, 'banana': 2})<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">defaultdict<\/span><span style=\"font-weight: 400;\"> c\u00f2n cho ph\u00e9p b\u1ea1n g\u00e1n ki\u1ec3u m\u1eb7c \u0111\u1ecbnh nh\u01b0 list, set\u2026 gi\u00fap code \u201cs\u1ea1ch\u201d h\u01a1n. Theo kinh nghi\u1ec7m c\u1ee7a nhi\u1ec1u l\u1eadp tr\u00ecnh vi\u00ean k\u1ef3 c\u1ef1u, <\/span><span style=\"font-weight: 400;\">defaultdict<\/span><span style=\"font-weight: 400;\"> ti\u1ebft ki\u1ec7m t\u1edbi <\/span><b>40 \u2013 50%<\/b><span style=\"font-weight: 400;\"> d\u00f2ng code x\u1eed l\u00fd logic li\u00ean quan \u0111\u1ebfn dictionary ph\u1ee9c t\u1ea1p.<\/span><\/p>\n<h3><b>itertools<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 <\/span><b>\u201ckho b\u00e1u\u201d<\/b><span style=\"font-weight: 400;\"> ch\u1ee9a h\u00e0ng lo\u1ea1t c\u00f4ng c\u1ee5 \u0111\u1ec3 l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c iterable (list, tuple\u2026). Th\u01b0 vi\u1ec7n n\u00e0y c\u00f3:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>combinations()<\/strong><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u1ea1o m\u1ecdi t\u1ed5 h\u1ee3p<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>permutations()<\/strong><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u1ea1o m\u1ecdi ho\u00e1n v\u1ecb<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>product()<\/strong><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u00ednh t\u00edch Descartes c\u1ee7a nhi\u1ec1u list<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>accumulate()<\/strong><span style=\"font-weight: 400;\"> \u0111\u1ec3 t\u00ednh t\u1ed5ng l\u0169y ti\u1ebfn\u2026<\/span><\/li>\n<\/ul>\n<h4><strong>combinations()<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">H\u00e0m <\/span><span style=\"font-weight: 400;\">combinations(iterable, r)<\/span><span style=\"font-weight: 400;\"> d\u00f9ng \u0111\u1ec3 t\u1ea1o ra <\/span><b>m\u1ecdi t\u1ed5 h\u1ee3p<\/b><span style=\"font-weight: 400;\"> (combination) c\u00f3 \u0111\u1ed9 d\u00e0i <\/span><span style=\"font-weight: 400;\">r<\/span><span style=\"font-weight: 400;\"> t\u1eeb <\/span><span style=\"font-weight: 400;\">iterable<\/span><span style=\"font-weight: 400;\">. M\u1ed7i t\u1ed5 h\u1ee3p \u0111\u01b0\u1ee3c t\u1ea1o ra kh\u00f4ng quan t\u00e2m th\u1ee9 t\u1ef1 (t\u1ee9c l\u00e0 <\/span><span style=\"font-weight: 400;\">(1,2)<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">(2,1)<\/span><span style=\"font-weight: 400;\"> \u0111\u01b0\u1ee3c xem l\u00e0 c\u00f9ng m\u1ed9t t\u1ed5 h\u1ee3p).<\/span><\/p>\n<p><b>V\u00ed d\u1ee5:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> itertools <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> combinations<\/span>\r\n\r\n<span style=\"font-weight: 400;\">items = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">combs = combinations(items, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">)\u00a0 <\/span><span style=\"font-weight: 400;\"># L\u1ea5y m\u1ecdi t\u1ed5 h\u1ee3p \u0111\u1ed9 d\u00e0i 2<\/span>\r\n\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"T\u1ed5 h\u1ee3p \u0111\u1ed9 d\u00e0i 2 t\u1eeb [1, 2, 3]:\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> c <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> combs:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(c)<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3:<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">T\u1ed5 h\u1ee3p \u0111\u1ed9 d\u00e0i <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> t\u1eeb [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">]:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>permutations()<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">H\u00e0m <\/span><span style=\"font-weight: 400;\">permutations(iterable, r)<\/span><span style=\"font-weight: 400;\"> d\u00f9ng \u0111\u1ec3 t\u1ea1o ra <\/span><b>m\u1ecdi ho\u00e1n v\u1ecb<\/b><span style=\"font-weight: 400;\"> (permutation) c\u00f3 \u0111\u1ed9 d\u00e0i <\/span><span style=\"font-weight: 400;\">r<\/span><span style=\"font-weight: 400;\"> t\u1eeb <\/span><span style=\"font-weight: 400;\">iterable<\/span><span style=\"font-weight: 400;\">. Kh\u00e1c v\u1edbi <\/span><span style=\"font-weight: 400;\">combinations()<\/span><span style=\"font-weight: 400;\">, ho\u00e1n v\u1ecb c\u00f3 <\/span><b>x\u00e9t \u0111\u1ebfn th\u1ee9 t\u1ef1<\/b><span style=\"font-weight: 400;\"> (t\u1ee9c l\u00e0 <\/span><span style=\"font-weight: 400;\">(1,2)<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">(2,1)<\/span><span style=\"font-weight: 400;\"> l\u00e0 hai ho\u00e1n v\u1ecb kh\u00e1c nhau).<\/span><\/p>\n<p><b>V\u00ed d\u1ee5:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> itertools <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> permutations<\/span>\r\n\r\n<span style=\"font-weight: 400;\">items = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">perms = permutations(items, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">)\u00a0 <\/span><span style=\"font-weight: 400;\"># L\u1ea5y m\u1ecdi ho\u00e1n v\u1ecb \u0111\u1ed9 d\u00e0i 2<\/span>\r\n\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"Ho\u00e1n v\u1ecb \u0111\u1ed9 d\u00e0i 2 t\u1eeb [1, 2, 3]:\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> p <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> perms:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(p)<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3:<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">Ho\u00e1n v\u1ecb \u0111\u1ed9 d\u00e0i <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> t\u1eeb [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">]:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>product()<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">H\u00e0m <\/span><span style=\"font-weight: 400;\">product(*iterables, repeat=1)<\/span><span style=\"font-weight: 400;\"> d\u00f9ng \u0111\u1ec3 t\u1ea1o ra <\/span><b>t\u00edch Descartes<\/b><span style=\"font-weight: 400;\"> (Cartesian product) c\u1ee7a c\u00e1c iterables. N\u00f3 s\u1ebd l\u1ea5y m\u1ed7i ph\u1ea7n t\u1eed c\u1ee7a iterable 1 k\u1ebft h\u1ee3p v\u1edbi m\u1ed7i ph\u1ea7n t\u1eed c\u1ee7a iterable 2, v.v.<\/span><\/p>\n<p><b>V\u00ed d\u1ee5 1: L\u1ea5y t\u00edch Descartes c\u1ee7a 2 list:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> itertools <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> product<\/span>\r\n\r\n<span style=\"font-weight: 400;\">list1 = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">list2 = [<\/span><span style=\"font-weight: 400;\">'A'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'B'<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n\r\n<span style=\"font-weight: 400;\">prod = product(list1, list2)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"T\u00edch Descartes c\u1ee7a [1, 2] v\u00e0 ['A', 'B']:\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> p <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> prod:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(p)<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3:<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">T\u00edch Descartes c\u1ee7a [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">] v\u00e0 [<\/span><span style=\"font-weight: 400;\">&#8216;A&#8217;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;B&#8217;<\/span><span style=\"font-weight: 400;\">]:<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;A&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;B&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;A&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;B&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>V\u00ed d\u1ee5 2: S\u1eed d\u1ee5ng tham s\u1ed1 <\/b><b>repeat<\/b><b>:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> itertools <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> product<\/span>\r\n\r\n<span style=\"font-weight: 400;\">chars = [<\/span><span style=\"font-weight: 400;\">'X'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'Y'<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n\r\n<span style=\"font-weight: 400;\"># product(chars, repeat=2) s\u1ebd coi nh\u01b0 product(chars, chars)<\/span>\r\n<span style=\"font-weight: 400;\"># =&gt; T\u1ea5t c\u1ea3 k\u1ebft h\u1ee3p 2 k\u00fd t\u1ef1 t\u1eeb ['X', 'Y'].<\/span>\r\n<span style=\"font-weight: 400;\">pairs = product(chars, repeat=<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"T\u00edch Descartes c\u1ee7a ['X', 'Y'] x 2 l\u1ea7n:\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> pair <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> pairs:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(pair)<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3:<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;X&#8217;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;X&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;X&#8217;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;Y&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;Y&#8217;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;X&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">(<\/span><span style=\"font-weight: 400;\">&#8216;Y&#8217;<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">&#8216;Y&#8217;<\/span><span style=\"font-weight: 400;\">)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong>accumulate()<\/strong><\/h4>\n<p><span style=\"font-weight: 400;\">H\u00e0m <\/span><span style=\"font-weight: 400;\">accumulate(iterable, func=operator.add, *, initial=None)<\/span><span style=\"font-weight: 400;\"> d\u00f9ng \u0111\u1ec3 t\u00ednh gi\u00e1 tr\u1ecb <\/span><b>l\u0169y ti\u1ebfn<\/b><span style=\"font-weight: 400;\"> tr\u00ean c\u00e1c ph\u1ea7n t\u1eed c\u1ee7a iterable. M\u1eb7c \u0111\u1ecbnh, n\u00f3 s\u1ebd c\u1ed9ng d\u1ed3n (s\u1eed d\u1ee5ng ph\u00e9p c\u1ed9ng). C\u00f3 th\u1ec3 truy\u1ec1n v\u00e0o ph\u00e9p to\u00e1n kh\u00e1c (nh\u01b0 nh\u00e2n, max, min, v.v.) \u0111\u1ec3 thay \u0111\u1ed5i c\u00e1ch t\u00ednh l\u0169y ti\u1ebfn.<\/span><\/p>\n<p><b>V\u00ed d\u1ee5 1: T\u00ednh l\u0169y ti\u1ebfn v\u1edbi ph\u00e9p c\u1ed9ng (m\u1eb7c \u0111\u1ecbnh):<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> itertools <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> accumulate<\/span>\r\n\r\n<span style=\"font-weight: 400;\">numbers = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">acc_sum = accumulate(numbers)\u00a0 <\/span><span style=\"font-weight: 400;\"># M\u1eb7c \u0111\u1ecbnh l\u00e0 ph\u00e9p c\u1ed9ng<\/span>\r\n\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"L\u0169y ti\u1ebfn (c\u1ed9ng) c\u1ee7a [1, 2, 3, 4]:\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> s <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> acc_sum:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(s)<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3:<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\"> \u00a0 <\/span><span style=\"font-weight: 400;\"># (1+2)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">6<\/span><span style=\"font-weight: 400;\"> \u00a0 <\/span><span style=\"font-weight: 400;\"># (1+2+3)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\"># (1+2+3+4)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><b>V\u00ed d\u1ee5 2: T\u00ednh l\u0169y ti\u1ebfn v\u1edbi ph\u00e9p nh\u00e2n:<\/b><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> itertools <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> accumulate<\/span>\r\n<span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> operator<\/span>\r\n\r\n<span style=\"font-weight: 400;\">numbers = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">acc_mul = accumulate(numbers, operator.mul)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"L\u0169y ti\u1ebfn (nh\u00e2n) c\u1ee7a [1, 2, 3, 4]:\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> m <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> acc_mul:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 print(m)<\/span><\/pre>\n<p><b>K\u1ebft qu\u1ea3:<\/b><\/p>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: left;\"><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> \u00a0 <\/span><span style=\"font-weight: 400;\"># (1*2)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">6<\/span><span style=\"font-weight: 400;\"> \u00a0 <\/span><span style=\"font-weight: 400;\"># (1*2*3)<\/span><span style=\"font-weight: 400;\"><br \/>\n<\/span><span style=\"font-weight: 400;\">24<\/span><span style=\"font-weight: 400;\">\u00a0 <\/span><span style=\"font-weight: 400;\"># (1*2*3*4)<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">T\u00f3m l\u1ea1i:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>combinations()<\/b><span style=\"font-weight: 400;\">: L\u1ea5y m\u1ecdi t\u1ed5 h\u1ee3p (kh\u00f4ng x\u00e9t th\u1ee9 t\u1ef1).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>permutations()<\/b><span style=\"font-weight: 400;\">: L\u1ea5y m\u1ecdi ho\u00e1n v\u1ecb (c\u00f3 x\u00e9t th\u1ee9 t\u1ef1).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>product()<\/b><span style=\"font-weight: 400;\">: T\u00ednh t\u00edch Descartes (k\u1ebft h\u1ee3p c\u00e1c ph\u1ea7n t\u1eed t\u1eeb nhi\u1ec1u iterable).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>accumulate()<\/b><span style=\"font-weight: 400;\">: T\u00ednh l\u0169y ti\u1ebfn (m\u1eb7c \u0111\u1ecbnh l\u00e0 c\u1ed9ng d\u1ed3n, c\u00f3 th\u1ec3 thay \u0111\u1ed5i b\u1eb1ng \u0111\u1ed1i s\u1ed1 <\/span><span style=\"font-weight: 400;\">func<\/span><span style=\"font-weight: 400;\">).<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 nh\u1eefng h\u00e0m h\u1eefu \u00edch trong <\/span><span style=\"font-weight: 400;\">itertools<\/span><span style=\"font-weight: 400;\"> khi l\u00e0m vi\u1ec7c v\u1edbi c\u00e1c thao t\u00e1c li\u00ean quan \u0111\u1ebfn t\u1ed5 h\u1ee3p, ho\u00e1n v\u1ecb, t\u00edch Descartes, v\u00e0 t\u1ed5ng\/t\u00edch l\u0169y ti\u1ebfn.<\/span><\/p>\n<h3><b>map()<\/b><b> v\u00e0 <\/b><b>filter()<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Hai h\u00e0m n\u00e0y l\u00e0 \u201cc\u00f4ng c\u1ee5 b\u1ecf t\u00fai\u201d cho vi\u1ec7c bi\u1ebfn \u0111\u1ed5i ho\u1eb7c l\u1ecdc d\u1eef li\u1ec7u nhanh:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">numbers = [<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">3<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">]<\/span>\r\n<span style=\"font-weight: 400;\">squared = list(map(<\/span><span style=\"font-weight: 400;\">lambda<\/span><span style=\"font-weight: 400;\"> x: x*x, numbers))<\/span>\r\n<span style=\"font-weight: 400;\">even = list(filter(<\/span><span style=\"font-weight: 400;\">lambda<\/span><span style=\"font-weight: 400;\"> x: x % <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> == <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">, numbers))<\/span>\r\n\r\n<span style=\"font-weight: 400;\">print(squared)\u00a0 <\/span><span style=\"font-weight: 400;\"># [1, 4, 9, 16, 25]<\/span>\r\n<span style=\"font-weight: 400;\">print(even) \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\"># [2, 4]<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e1c l\u1eadp tr\u00ecnh vi\u00ean th\u00edch d\u00f9ng list comprehension h\u01a1n, nh\u01b0ng <\/span><span style=\"font-weight: 400;\">map()<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">filter()<\/span><span style=\"font-weight: 400;\"> v\u1eabn ph\u1ed5 bi\u1ebfn trong m\u1ed9t s\u1ed1 tr\u01b0\u1eddng h\u1ee3p c\u00f3 h\u00e0m s\u1eb5n ho\u1eb7c khi c\u1ea7n chain nhi\u1ec1u h\u00e0m li\u00ean ti\u1ebfp.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cac_lenh_trong_Python_giup_xu_ly_file_va_quan_ly_tai_nguyen\"><\/span><b>C\u00e1c l\u1ec7nh trong Python gi\u00fap x\u1eed l\u00fd file v\u00e0 qu\u1ea3n l\u00fd t\u00e0i nguy\u00ean<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>with open()<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Qu\u00ean \u0111\u00f3ng file l\u00e0 \u201cs\u00e1t th\u1ee7 th\u1ea7m l\u1eb7ng\u201d g\u00e2y r\u00f2 r\u1ec9 t\u00e0i nguy\u00ean. Trong khi n\u1ebfu d\u00f9ng <\/span><span style=\"font-weight: 400;\">with open()<\/span><span style=\"font-weight: 400;\">, Python s\u1ebd t\u1ef1 \u0111\u1ed9ng \u0111\u00f3ng file ngay khi tho\u00e1t kh\u1ed1i l\u1ec7nh:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">with<\/span><span style=\"font-weight: 400;\"> open(<\/span><span style=\"font-weight: 400;\">'data.txt'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'r'<\/span><span style=\"font-weight: 400;\">) <\/span><span style=\"font-weight: 400;\">as<\/span><span style=\"font-weight: 400;\"> file:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 data = file.read()<\/span>\r\n<span style=\"font-weight: 400;\"># T\u1ea1i \u0111\u00e2y file \u0111\u00e3 \u0111\u01b0\u1ee3c \u0111\u00f3ng<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e1c di\u1ec5n \u0111\u00e0n h\u01b0\u1edbng d\u1eabn cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u khuy\u1ebfn kh\u00edch s\u1eed d\u1ee5ng <\/span><span style=\"font-weight: 400;\">with open()<\/span><span style=\"font-weight: 400;\"> thay cho c\u00e1ch m\u1edf file truy\u1ec1n th\u1ed1ng <\/span><span style=\"font-weight: 400;\">f = open()<\/span><span style=\"font-weight: 400;\">, v\u00ec s\u1ef1 ti\u1ec7n l\u1ee3i v\u00e0 an to\u00e0n.<\/span><\/p>\n<h3><b>os<\/b><b> v\u00e0 <\/b><b>shutil<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u0110\u1ec3 thao t\u00e1c v\u1edbi file, th\u01b0 m\u1ee5c \u1edf c\u1ea5p h\u1ec7 th\u1ed1ng, b\u1ea1n kh\u00f4ng th\u1ec3 b\u1ecf qua hai \u201cth\u01b0 vi\u1ec7n g\u1ed1c\u201d n\u00e0y:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>os<\/b><span style=\"font-weight: 400;\">: T\u1ea1o, x\u00f3a, \u0111\u1ed5i t\u00ean, di chuy\u1ec3n file\/th\u01b0 m\u1ee5c, l\u1ea5y th\u00f4ng tin m\u00f4i tr\u01b0\u1eddng\u2026<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>shutil<\/b><span style=\"font-weight: 400;\">: Sao ch\u00e9p file\/th\u01b0 m\u1ee5c, n\u00e9n\/gi\u1ea3i n\u00e9n, thao t\u00e1c ph\u1ee9c t\u1ea1p h\u01a1n v\u1edbi h\u1ec7 th\u1ed1ng.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> os<\/span>\r\n<span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> shutil<\/span>\r\n\r\n<span style=\"font-weight: 400;\">os.rename(<\/span><span style=\"font-weight: 400;\">'old_name.txt'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'new_name.txt'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">shutil.copy(<\/span><span style=\"font-weight: 400;\">'new_name.txt'<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'backup_name.txt'<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Cac_lenh_trong_Python_nang_cao\"><\/span><b>C\u00e1c l\u1ec7nh trong Python n\u00e2ng cao<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>List\/Dictionary Comprehension<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 m\u1ed9t c\u00fa ph\u00e1p gi\u00fap t\u1ea1o List v\u00e0 Dict theo \u0111i\u1ec1u ki\u1ec7n m\u1ed9t c\u00e1ch nhanh ch\u00f3ng.<\/span><\/p>\n<h4><b>List Comprehension<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5 t\u1ea1o ra list trong range 10 v\u00e0 s\u1ed1 \u0111\u00f3 chia h\u1ebft cho 2:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">numbers = [x <\/span><span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> x <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> range(<\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">) <\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> x % <\/span><span style=\"font-weight: 400;\">2<\/span><span style=\"font-weight: 400;\"> == <\/span><span style=\"font-weight: 400;\">0<\/span><span style=\"font-weight: 400;\">]<\/span><\/pre>\n<h4><b>Dictionary Comprehension<\/b><\/h4>\n<p><span style=\"font-weight: 400;\">T\u1ea1o ra Dict m\u1edbi khi m\u00e0 gi\u00e1 c\u1ee7a c\u00e1c lo\u1ea1i hoa qu\u1ea3 gi\u1ea3m gi\u00e1 \u0111i 10%:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">items = {<\/span><span style=\"font-weight: 400;\">'apple'<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">10<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'banana'<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">5<\/span><span style=\"font-weight: 400;\">, <\/span><span style=\"font-weight: 400;\">'orange'<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">8<\/span><span style=\"font-weight: 400;\">}<\/span>\r\n<span style=\"font-weight: 400;\">discounted = {k: v*<\/span><span style=\"font-weight: 400;\">0.9<\/span> <span style=\"font-weight: 400;\">for<\/span><span style=\"font-weight: 400;\"> (k, v) <\/span><span style=\"font-weight: 400;\">in<\/span><span style=\"font-weight: 400;\"> items.items()}<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Trong Python, \u201ccode ng\u1eafn g\u1ecdn\u201d kh\u00f4ng ph\u1ea3i l\u00fac n\u00e0o c\u0169ng l\u00e0 m\u1ee5c ti\u00eau t\u1ed1i th\u01b0\u1ee3ng, nh\u01b0ng l\u1eadp tr\u00ecnh vi\u00ean cho bi\u1ebft h\u1ecd y\u00eau th\u00edch comprehension v\u00ec t\u00ednh s\u00fac t\u00edch v\u00e0 d\u1ec5 \u0111\u1ecdc khi d\u00f9ng \u0111\u00fang b\u1ed1i c\u1ea3nh.<\/span><\/p>\n<h3><b>F-string<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">F-string (xu\u1ea5t hi\u1ec7n t\u1eeb Python 3.6) l\u00e0 \u201cv\u0169 kh\u00ed\u201d \u0111\u1ecbnh d\u1ea1ng chu\u1ed7i. Thay v\u00ec:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">name = <\/span><span style=\"font-weight: 400;\">\"Alice\"<\/span>\r\n<span style=\"font-weight: 400;\">age = <\/span><span style=\"font-weight: 400;\">25<\/span>\r\n<span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">\"T\u00ean: \"<\/span><span style=\"font-weight: 400;\"> + name + <\/span><span style=\"font-weight: 400;\">\", Tu\u1ed5i: \"<\/span><span style=\"font-weight: 400;\"> + str(age))<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">Ch\u00fang ta c\u00f3:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">f\"T\u00ean: <\/span><span style=\"font-weight: 400;\">{name}<\/span><span style=\"font-weight: 400;\">, Tu\u1ed5i: <\/span><span style=\"font-weight: 400;\">{age}<\/span><span style=\"font-weight: 400;\">\"<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea1n th\u1eadm ch\u00ed c\u00f3 th\u1ec3 nh\u00fang h\u00e0m:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">print(<\/span><span style=\"font-weight: 400;\">f\"\u0110\u1ed9 d\u00e0i t\u00ean: <\/span><span style=\"font-weight: 400;\">{len(name)}<\/span><span style=\"font-weight: 400;\">\"<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">C\u00e1c Senior Developer khi \u0111\u01b0\u1ee3c \u0111\u01b0\u1ee3c h\u1ecfi tr\u00ean c\u00e1c di\u1ec5n \u0111\u00e0n chuy\u00ean m\u00f4n chuy\u1ec3n sang d\u00f9ng F-string ngay khi n\u00f3 ra m\u1eaft, v\u00ec s\u1ef1 ti\u1ec7n l\u1ee3i kh\u00f4ng th\u1ec3 ch\u1ed1i c\u00e3i.<\/span><\/p>\n<h3><b>Decorators (c\u01a1 b\u1ea3n)<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Decorator cho ph\u00e9p th\u00eam\/b\u1edbt t\u00ednh n\u0103ng v\u00e0o h\u00e0m m\u00e0 kh\u00f4ng thay \u0111\u1ed5i code g\u1ed1c. V\u00ed d\u1ee5 m\u1ed9t decorator t\u00ednh th\u1eddi gian ch\u1ea1y h\u00e0m:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> time<\/span>\r\n\r\n<span style=\"font-weight: 400;\">def<\/span><span style=\"font-weight: 400;\"> timing_decorator<\/span><span style=\"font-weight: 400;\">(func)<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">def<\/span><span style=\"font-weight: 400;\"> wrapper<\/span><span style=\"font-weight: 400;\">(*args, **kwargs)<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 start = time.time()<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 result = func(*args, **kwargs)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 end = time.time()<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 print(<\/span><span style=\"font-weight: 400;\">f\"H\u00e0m <\/span><span style=\"font-weight: 400;\">{func.__name__}<\/span><span style=\"font-weight: 400;\"> ch\u1ea1y h\u1ebft <\/span><span style=\"font-weight: 400;\">{end - start}<\/span><span style=\"font-weight: 400;\"> gi\u00e2y.\"<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> result<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> wrapper<\/span>\r\n\r\n<span style=\"font-weight: 400;\">@timing_decorator<\/span>\r\n<span style=\"font-weight: 400;\">def<\/span><span style=\"font-weight: 400;\"> heavy_task<\/span><span style=\"font-weight: 400;\">()<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 time.sleep(<\/span><span style=\"font-weight: 400;\">1<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">heavy_task()\u00a0 <\/span><span style=\"font-weight: 400;\"># In ra th\u1eddi gian ch\u1ea1y<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">L\u1eadp tr\u00ecnh vi\u00ean Python th\u00edch s\u1eed d\u1ee5ng c\u00fa ph\u00e1p n\u00e0y nh\u1ea5t l\u00e0 trong vi\u1ec7c logging, caching (nh\u01b0 <\/span><span style=\"font-weight: 400;\">functools.lru_cache<\/span><span style=\"font-weight: 400;\">) ho\u1eb7c ki\u1ec3m so\u00e1t truy c\u1eadp.<\/span><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_cac_lenh_trong_Python\"><\/span><b>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 c\u00e1c l\u1ec7nh trong Python<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><b>T\u00f4i n\u00ean h\u1ecdc l\u1ec7nh n\u00e0o tr\u01b0\u1edbc?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">N\u1ebfu b\u1ea1n <\/span><i><span style=\"font-weight: 400;\">m\u1edbi<\/span><\/i><span style=\"font-weight: 400;\"> l\u00e0m quen v\u1edbi Python, h\u00e3y b\u1eaft \u0111\u1ea7u t\u1eeb nh\u1eefng l\u1ec7nh \u201cnh\u1ecf nh\u01b0ng c\u00f3 v\u00f5\u201d:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">enumerate()<\/span><span style=\"font-weight: 400;\"> \u2013 c\u1ef1c k\u1ef3 h\u1eefu d\u1ee5ng khi duy\u1ec7t list.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">zip()<\/span><span style=\"font-weight: 400;\"> \u2013 g\u1ed9p d\u1eef li\u1ec7u t\u1eeb nhi\u1ec1u list.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">with open()<\/span><span style=\"font-weight: 400;\"> \u2013 x\u1eed l\u00fd file an to\u00e0n.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Nh\u1eefng l\u1ec7nh n\u00e0y c\u00f3 kh\u1ea3 n\u0103ng \u00e1p d\u1ee5ng r\u1ed9ng r\u00e3i trong h\u1ea7u h\u1ebft d\u1ef1 \u00e1n.<\/span><\/p>\n<h3><b>Python 2 c\u00f3 d\u00f9ng \u0111\u01b0\u1ee3c c\u00e1c l\u1ec7nh n\u00e0y kh\u00f4ng?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>enumerate()<\/b><b>, <\/b><b>zip()<\/b><b>, <\/b><b>any()<\/b><b>, <\/b><b>all()<\/b><span style=\"font-weight: 400;\">: \u0110\u1ec1u c\u00f3 tr\u00ean Python 2.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>Walrus Operator (:=<\/strong><span style=\"font-weight: 400;\"><strong>)<\/strong>: Ch\u1ec9 xu\u1ea5t hi\u1ec7n t\u1eeb Python 3.8+<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Ngo\u00e0i ra, m\u1ed9t s\u1ed1 th\u01b0 vi\u1ec7n c\u00f3 th\u1ec3 ch\u1ec9 h\u1ed7 tr\u1ee3 phi\u00ean b\u1ea3n Python 3 tr\u1edf l\u00ean. N\u1ebfu v\u1eabn c\u00f2n bu\u1ed9c ph\u1ea3i d\u00f9ng Python 2, b\u1ea1n c\u1ea7n xem k\u1ef9 t\u00e0i li\u1ec7u ho\u1eb7c d\u00f9ng c\u00e1c phi\u00ean b\u1ea3n th\u01b0 vi\u1ec7n t\u01b0\u01a1ng th\u00edch.<\/span><\/p>\n<h3><b>Khi n\u00e0o d\u00f9ng v\u00f2ng l\u1eb7p for, khi n\u00e0o d\u00f9ng <\/b><b>map()<\/b><b>\/<\/b><b>filter()<\/b><b> hay comprehension?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>V\u00f2ng l\u1eb7p for<\/b><span style=\"font-weight: 400;\">: Ph\u00f9 h\u1ee3p v\u1edbi logic ph\u1ee9c t\u1ea1p, nhi\u1ec1u \u0111i\u1ec1u ki\u1ec7n, nhi\u1ec1u bi\u1ebfn trung gian.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Comprehension<\/b><span style=\"font-weight: 400;\">: Khi b\u1ea1n mu\u1ed1n truy xu\u1ea5t\/bi\u1ebfn \u0111\u1ed5i danh s\u00e1ch m\u1ed9t c\u00e1ch g\u1ecdn, r\u00e0nh m\u1ea1ch.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>map()<\/b><b>, <\/b><b>filter()<\/b><span style=\"font-weight: 400;\">: Khi b\u1ea1n c\u00f3 m\u1ed9t h\u00e0m r\u00f5 r\u00e0ng c\u1ea7n \u00e1p d\u1ee5ng l\u00ean m\u1ed7i ph\u1ea7n t\u1eed ho\u1eb7c c\u1ea7n l\u1ecdc c\u00e1c gi\u00e1 tr\u1ecb th\u1ecfa m\u00e3n \u0111i\u1ec1u ki\u1ec7n duy nh\u1ea5t.<\/span><\/li>\n<\/ul>\n<h3><b>Code ng\u1eafn g\u1ecdn c\u00f3 lu\u00f4n t\u1ed1t h\u01a1n kh\u00f4ng?<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">\u01afu ti\u00ean s\u1ef1 r\u00f5 r\u00e0ng, d\u1ec5 b\u1ea3o tr\u00ec. N\u1ebfu code tr\u1edf n\u00ean \u201cb\u00ed hi\u1ec3m\u201d khi\u1ebfn \u0111\u1ed3ng \u0111\u1ed9i \u0111\u1ecdc m\u00e3i kh\u00f4ng hi\u1ec3u, th\u00ec \u0111\u00f4i khi v\u00f2ng l\u1eb7p for truy\u1ec1n th\u1ed1ng l\u1ea1i \u201can to\u00e0n\u201d h\u01a1n. H\u00e3y c\u00e2n b\u1eb1ng gi\u1eefa \u201c\u0111\u1eb9p\u201d v\u00e0 \u201cd\u1ec5 hi\u1ec3u\u201d.<\/span><\/p>\n<h3><b>T\u00ecm hi\u1ec3u th\u00eam v\u1ec1 c\u00e1c l\u1ec7nh trong Python \u1edf \u0111\u00e2u?<\/b><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u00e0i li\u1ec7u Python ch\u00ednh th\u1ee9c<\/b><span style=\"font-weight: 400;\">: N\u01a1i t\u1ed1t nh\u1ea5t \u0111\u1ec3 \u0111\u1ecdc chi ti\u1ebft.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Blog ITviec<\/b><span style=\"font-weight: 400;\">, <\/span><b>Stack Overflow<\/b><span style=\"font-weight: 400;\">, <\/span><b>Reddit<\/b><span style=\"font-weight: 400;\">: Ngu\u1ed3n chia s\u1ebb kinh nghi\u1ec7m th\u1ef1c chi\u1ebfn t\u1eeb c\u1ed9ng \u0111\u1ed3ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>PyPI<\/b><span style=\"font-weight: 400;\">: C\u1eadp nh\u1eadt xu h\u01b0\u1edbng th\u01b0 vi\u1ec7n m\u1edbi, nh\u1eefng b\u1ea3n ph\u00e1t h\u00e0nh quan tr\u1ecdng.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_cac_lenh_trong_Python\"><\/span><b>T\u1ed5ng k\u1ebft c\u00e1c l\u1ec7nh trong Python<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Python \u1ea9n ch\u1ee9a v\u00f4 v\u00e0n l\u1ec7nh t\u01b0\u1edfng ch\u1eebng nh\u1ecf nh\u1eb7t, nh\u01b0ng l\u1ea1i c\u00f3 s\u1ee9c \u1ea3nh h\u01b0\u1edfng l\u1edbn \u0111\u1ebfn hi\u1ec7u su\u1ea5t v\u00e0 c\u1ea5u tr\u00fac code. T\u1eeb vi\u1ec7c duy\u1ec7t list v\u1edbi <\/span><span style=\"font-weight: 400;\">enumerate()<\/span><span style=\"font-weight: 400;\">, g\u1ed9p d\u1eef li\u1ec7u b\u1eb1ng <\/span><span style=\"font-weight: 400;\">zip()<\/span><span style=\"font-weight: 400;\">, \u0111\u1ebfn vi\u1ec7c \u201cma thu\u1eadt ho\u00e1\u201d v\u1edbi Walrus Operator hay t\u00f4 \u0111i\u1ec3m code b\u1eb1ng Decorators, t\u1ea5t c\u1ea3 g\u1ed9p l\u1ea1i t\u1ea1o n\u00ean m\u1ed9t \u201ckho v\u0169 kh\u00ed\u201d l\u1ee3i h\u1ea1i, gi\u00fap b\u1ea1n:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Ti\u1ebft ki\u1ec7m th\u1eddi gian<\/span><span style=\"font-weight: 400;\"> v\u00e0 c\u00f4ng s\u1ee9c khi vi\u1ebft c\u00e1c thao t\u00e1c l\u1eb7p \u0111i l\u1eb7p l\u1ea1i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">T\u1ed1i \u01b0u code<\/span><span style=\"font-weight: 400;\"> theo h\u01b0\u1edbng ng\u1eafn g\u1ecdn nh\u01b0ng v\u1eabn r\u00f5 r\u00e0ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">M\u1edf r\u1ed9ng kh\u1ea3 n\u0103ng<\/span><span style=\"font-weight: 400;\"> x\u1eed l\u00fd d\u1eef li\u1ec7u, qu\u1ea3n l\u00fd t\u00e0i nguy\u00ean.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">S\u1ef1 kh\u00e1c bi\u1ec7t gi\u1eefa ng\u01b0\u1eddi m\u1edbi (Fresher) v\u00e0 ng\u01b0\u1eddi d\u00e0y d\u1ea1n kinh nghi\u1ec7m (Senior) trong Python th\u01b0\u1eddng n\u1eb1m \u1edf t\u01b0 duy v\u00e0 c\u00e1ch ti\u1ebfp c\u1eadn h\u01a1n l\u00e0 danh s\u00e1ch c\u00e1c l\u1ec7nh c\u1ee5 th\u1ec3. Trong khi ng\u01b0\u1eddi m\u1edbi th\u01b0\u1eddng ch\u00fa tr\u1ecdng ho\u00e0n th\u00e0nh ch\u1ee9c n\u0103ng c\u01a1 b\u1ea3n, ng\u01b0\u1eddi \u201cl\u00e3o luy\u1ec7n\u201d l\u1ea1i hi\u1ec3u s\u00e2u v\u1ec1 c\u1ea5u tr\u00fac ng\u00f4n ng\u1eef, bi\u1ebft t\u1ed1i \u01b0u h\u00f3a lu\u1ed3ng x\u1eed l\u00fd v\u00e0 vi\u1ebft code mang t\u00ednh \u201cPythonic\u201d \u2013 ng\u1eafn g\u1ecdn, r\u00f5 r\u00e0ng, d\u1ec5 b\u1ea3o tr\u00ec. H\u1ecd kh\u00f4ng ch\u1ec9 n\u1eafm c\u00f4ng c\u1ee5 s\u1eb5n c\u00f3, m\u00e0 c\u00f2n v\u1eadn d\u1ee5ng ch\u00fang m\u1ed9t c\u00e1ch linh ho\u1ea1t, k\u1ebft h\u1ee3p v\u1edbi th\u00f3i quen ki\u1ec3m so\u00e1t l\u1ed7i ch\u1eb7t ch\u1ebd, qu\u1ea3n l\u00fd t\u00e0i nguy\u00ean h\u1ee3p l\u00fd. Ch\u00ednh nh\u1eefng \u0111i\u1ec1u n\u00e0y gi\u00fap t\u1ea1o ra kh\u00e1c bi\u1ec7t v\u1ec1 hi\u1ec7u qu\u1ea3, t\u00ednh \u1ed5n \u0111\u1ecbnh v\u00e0 kh\u1ea3 n\u0103ng m\u1edf r\u1ed9ng c\u1ee7a s\u1ea3n ph\u1ea9m cu\u1ed1i c\u00f9ng.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ch\u1eafc h\u1eb3n b\u1ea1n \u0111\u00e3 t\u1eebng nghe c\u00e2u n\u00f3i vui \u201cTrong th\u1ebf gi\u1edbi Python, h\u1ea7u nh\u01b0 vi\u1ec7c g\u00ec c\u0169ng c\u00f3 th\u1ec3 gi\u1ea3i quy\u1ebft ch\u1ec9 b\u1eb1ng m\u1ed9t v\u00e0i d\u00f2ng code\u201d. S\u1ef1 th\u1ef1c l\u00e0 Python mang l\u1ea1i r\u1ea5t nhi\u1ec1u l\u1ec7nh \u201ckho b\u00e1u\u201d m\u00e0 n\u1ebfu b\u1ea1n khai th\u00e1c th\u00e0nh th\u1ea1o, t\u1ed1c \u0111\u1ed9 ph\u00e1t tri\u1ec3n d\u1ef1 \u00e1n s\u1ebd nhanh h\u01a1n [&hellip;]<\/p>\n","protected":false},"author":222,"featured_media":84628,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-84505","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer - ITviec Blog<\/title>\n<meta name=\"description\" content=\"L\u01b0u l\u1ea1i c\u00e1c l\u1ec7nh trong Python m\u00e0 Senior Developer th\u01b0\u1eddng s\u1eed d\u1ee5ng nh\u01b0 zip(), any(), all(), Walrus Operator, \u0111\u1ebfn c\u00e1c th\u01b0 vi\u1ec7n gi\u00fap t\u1ed1i \u01b0u code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer\" \/>\n<meta property=\"og:description\" content=\"Ch\u1eafc h\u1eb3n b\u1ea1n \u0111\u00e3 t\u1eebng nghe c\u00e2u n\u00f3i vui \u201cTrong th\u1ebf gi\u1edbi Python, h\u1ea7u nh\u01b0 vi\u1ec7c g\u00ec c\u0169ng c\u00f3 th\u1ec3 gi\u1ea3i quy\u1ebft ch\u1ec9 b\u1eb1ng m\u1ed9t v\u00e0i d\u00f2ng code\u201d. S\u1ef1 th\u1ef1c l\u00e0 Python mang\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-22T16:27:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cac-lenh-trong-python-vippro.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"1500\" \/>\n\t<meta property=\"og:image:height\" content=\"790\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nguy\u1ec5n H\u1eefu V\u0103n\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nguy\u1ec5n H\u1eefu V\u0103n\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer - ITviec Blog","description":"L\u01b0u l\u1ea1i c\u00e1c l\u1ec7nh trong Python m\u00e0 Senior Developer th\u01b0\u1eddng s\u1eed d\u1ee5ng nh\u01b0 zip(), any(), all(), Walrus Operator, \u0111\u1ebfn c\u00e1c th\u01b0 vi\u1ec7n gi\u00fap t\u1ed1i \u01b0u code.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/","og_locale":"vi_VN","og_type":"article","og_title":"C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer","og_description":"Ch\u1eafc h\u1eb3n b\u1ea1n \u0111\u00e3 t\u1eebng nghe c\u00e2u n\u00f3i vui \u201cTrong th\u1ebf gi\u1edbi Python, h\u1ea7u nh\u01b0 vi\u1ec7c g\u00ec c\u0169ng c\u00f3 th\u1ec3 gi\u1ea3i quy\u1ebft ch\u1ec9 b\u1eb1ng m\u1ed9t v\u00e0i d\u00f2ng code\u201d. S\u1ef1 th\u1ef1c l\u00e0 Python mang","og_url":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2025-02-22T16:27:04+00:00","og_image":[{"width":1500,"height":790,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cac-lenh-trong-python-vippro.jpeg","type":"image\/jpeg"}],"author":"Nguy\u1ec5n H\u1eefu V\u0103n","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Nguy\u1ec5n H\u1eefu V\u0103n","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"12 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/"},"author":{"name":"Nguy\u1ec5n H\u1eefu V\u0103n","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/a77cc13f89eaa58f59d8772448febe5f"},"headline":"C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer","datePublished":"2025-02-22T16:27:04+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/"},"wordCount":2937,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cac-lenh-trong-python-vippro.jpeg","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/","url":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/","name":"C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cac-lenh-trong-python-vippro.jpeg","datePublished":"2025-02-22T16:27:04+00:00","description":"L\u01b0u l\u1ea1i c\u00e1c l\u1ec7nh trong Python m\u00e0 Senior Developer th\u01b0\u1eddng s\u1eed d\u1ee5ng nh\u01b0 zip(), any(), all(), Walrus Operator, \u0111\u1ebfn c\u00e1c th\u01b0 vi\u1ec7n gi\u00fap t\u1ed1i \u01b0u code.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cac-lenh-trong-python-vippro.jpeg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2025\/02\/cac-lenh-trong-python-vippro.jpeg","width":1500,"height":790,"caption":"c\u00e1c l\u1ec7nh trong python - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/cac-lenh-trong-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"C\u00e1c l\u1ec7nh trong Python gi\u00fap ph\u00e2n bi\u1ec7t Fresher v\u00e0 Senior Developer"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/a77cc13f89eaa58f59d8772448febe5f","name":"Nguy\u1ec5n H\u1eefu V\u0103n","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/TR-Nguyen-Huu-Van-vippro-e1712136004193-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/TR-Nguyen-Huu-Van-vippro-e1712136004193-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/TR-Nguyen-Huu-Van-vippro-e1712136004193-100x100.jpg","caption":"Nguy\u1ec5n H\u1eefu V\u0103n"},"url":"https:\/\/itviec.com\/blog\/author\/nguyen-huu-van-2\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/84505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/222"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=84505"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/84505\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/84628"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=84505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=84505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=84505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}