Created
October 25, 2022 15:58
-
-
Save hvnsweeting/2cefe556dd56f74491b3dd6e191ab0fd to your computer and use it in GitHub Desktop.
Học Python Hà Nội Sài Gòn TP HCM 2022 lớp pymi.vn 2210
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "d6827570", | |
"metadata": {}, | |
"source": [ | |
"# Pymi.vn - lesson 2" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "167e8f6d", | |
"metadata": {}, | |
"source": [ | |
"## number (cont)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "1ff6b7a8", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"14" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"2 + 3 * 4" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "56dd9ea5", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"20" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"(2 + 3) * 4" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "2a04986b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2.0" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"4/2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "b99234cb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2.5" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"5/2" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "51e6e565", | |
"metadata": {}, | |
"source": [ | |
"// - floor division" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "32468f09", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"5//2" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9546456e", | |
"metadata": {}, | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "938c4575", | |
"metadata": {}, | |
"source": [ | |
"### power" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "fcf9c117", | |
"metadata": {}, | |
"source": [ | |
"2 mu 3 == 8" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "633b56d7", | |
"metadata": {}, | |
"source": [ | |
"## 2 to the power of 3" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "580e70c9", | |
"metadata": {}, | |
"source": [ | |
"## day khong phai phep luy thua" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"id": "39f6dbcd", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"2 ^ 3 " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "5382f7b4", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "5a2e83e8", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"8" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"2 ** 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "44fc3ee6", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"id": "00322ef4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1.4142135623730951" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"2 ** (1/2)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "7be223f1", | |
"metadata": {}, | |
"source": [ | |
"## bấm ctrl-C để dừng tính" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "80886f12", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "bf9fadc6", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "27600d3f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "7e6182c8", | |
"metadata": {}, | |
"source": [ | |
"### modulo" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"id": "eb41d466", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"5 % 2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"id": "71c78b76", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"4 % 2 " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"id": "4d01dd6b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"4 % 2 == 0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "dba54f5b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "2a906a1f", | |
"metadata": {}, | |
"source": [ | |
"## giảm kích thước bài tóan có tính chu kỳ" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "40b47679", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "21142749", | |
"metadata": {}, | |
"source": [ | |
"## bói toán" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "56f853e1", | |
"metadata": {}, | |
"source": [ | |
"## 2022 - nhâm dần" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "bb9a0fca", | |
"metadata": {}, | |
"source": [ | |
"## 2012?? - nhâm thìn? " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "dd806e0e", | |
"metadata": {}, | |
"source": [ | |
"2010 - **** dần " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "fa1b7fc2", | |
"metadata": {}, | |
"source": [ | |
"## thiên can - địa chi " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "aa281de7", | |
"metadata": {}, | |
"source": [ | |
"## 12 địa chi\n", | |
"- tí \n", | |
"- sửu\n", | |
"- dần\n", | |
"- mão\n", | |
"- thìn \n", | |
"- tỵ \n", | |
"- ngọ\n", | |
"- mùi\n", | |
"- thân\n", | |
"- dậu\n", | |
"- tuất \n", | |
"- hợi " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "52ee1550", | |
"metadata": {}, | |
"source": [ | |
"## 10 thiên can \n", | |
"- canh\n", | |
"- tân\n", | |
"- nhâm\n", | |
"- quý\n", | |
"- giáp\n", | |
"- ất\n", | |
"- bính \n", | |
"- đinh \n", | |
"- mậu\n", | |
"- kỷ" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b2c4ff2a", | |
"metadata": {}, | |
"source": [ | |
"## 1990 - canh ngọ" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"id": "33b5cd37", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"8" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"(2022-1990)%12" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "f52c8d4a", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "8ef85e96", | |
"metadata": {}, | |
"source": [ | |
"## 1269 " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"id": "60351e97", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"9" | |
] | |
}, | |
"execution_count": 20, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"(2022-1269) % 12" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "59acfeff", | |
"metadata": {}, | |
"source": [ | |
"https://canchi.pymi.vn/" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "6e8187c9", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "2dfd3676", | |
"metadata": {}, | |
"source": [ | |
"### complex" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"id": "b9228a5e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"(4+6j)" | |
] | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"1 + 2j + 3 + 4j" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"id": "ad1778c4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"complex" | |
] | |
}, | |
"execution_count": 22, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"type(4+6j)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "e1f5d726", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 132, | |
"id": "14ff1b95", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import math" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 135, | |
"id": "adf947da", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1.4142135623730951" | |
] | |
}, | |
"execution_count": 135, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"math.sqrt(2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 133, | |
"id": "75963388", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"3.141592653589793" | |
] | |
}, | |
"execution_count": 133, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"math.pi" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 134, | |
"id": "fc0f87e6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0.8939966636005579" | |
] | |
}, | |
"execution_count": 134, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"math.sin(90)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 136, | |
"id": "e8e32f27", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1.0" | |
] | |
}, | |
"execution_count": 136, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"math.sin(math.pi/2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 137, | |
"id": "bed1758b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"720" | |
] | |
}, | |
"execution_count": 137, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"math.factorial(6)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 139, | |
"id": "0836e18d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"123" | |
] | |
}, | |
"execution_count": 139, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"abs(-123)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "8c46fe0b", | |
"metadata": {}, | |
"source": [ | |
"## comparison" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"id": "050f9e9b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 23, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"2 < 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"id": "b757faa4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"2 > 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"id": "54b0fcd5", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"bool" | |
] | |
}, | |
"execution_count": 25, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"type(2>3)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "eeada7ae", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "33662807", | |
"metadata": {}, | |
"source": [ | |
"## chữ T và F viết hoa" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"id": "04fdca57", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 26, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"id": "1572077c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"False" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"id": "0bb072ad", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"bool" | |
] | |
}, | |
"execution_count": 29, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"type(True)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "6ed2401f", | |
"metadata": {}, | |
"source": [ | |
"## boolean uk /ˈbuːliən/ us\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "ac89788d", | |
"metadata": {}, | |
"source": [ | |
"## clean" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"id": "11bcbc42", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 30, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"1 != 1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 31, | |
"id": "68fe4a23", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"1 == 1" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a94b7ce5", | |
"metadata": {}, | |
"source": [ | |
"## các phép tóan với boolean" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "0946d535", | |
"metadata": {}, | |
"source": [ | |
"## and - và" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"id": "14ba53bd", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 32, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True and True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 33, | |
"id": "86d237b6", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 33, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True and False" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 34, | |
"id": "768a2009", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 34, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"False and True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 35, | |
"id": "232e81d0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 35, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"False and False" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a0d69909", | |
"metadata": {}, | |
"source": [ | |
"## or - hoặc" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"id": "c8922fc0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 36, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True or True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"id": "2d8b3a32", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 37, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True or False" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 38, | |
"id": "73cc4a91", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 38, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"False or True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 39, | |
"id": "cf7b23bf", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 39, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"False or False" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "5b280cfe", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b6bf15be", | |
"metadata": {}, | |
"source": [ | |
"## not" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 40, | |
"id": "d6afbcac", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 40, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"not True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 41, | |
"id": "78353163", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 41, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"not False" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "c12a02b6", | |
"metadata": {}, | |
"source": [ | |
"### don't do this" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 42, | |
"id": "1fd6e951", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 42, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"not True == False" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 43, | |
"id": "ee66c831", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 43, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"not False == True" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "86437b14", | |
"metadata": {}, | |
"source": [ | |
"### do this" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 44, | |
"id": "18052455", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 44, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"not True is False" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 45, | |
"id": "ba2347b0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 45, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"not False is True" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "38e3364e", | |
"metadata": {}, | |
"source": [ | |
"## câu hỏi 1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 46, | |
"id": "4367b961", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "ZeroDivisionError", | |
"evalue": "division by zero", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/2354412189.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" | |
] | |
} | |
], | |
"source": [ | |
"1/0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 52, | |
"id": "86be60ec", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 52, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True or 1/0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 53, | |
"id": "021b1acd", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "ZeroDivisionError", | |
"evalue": "division by zero", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/3147863620.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mTrue\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" | |
] | |
} | |
], | |
"source": [ | |
"True and 1/0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 54, | |
"id": "8df58dea", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "ZeroDivisionError", | |
"evalue": "division by zero", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/2917809745.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" | |
] | |
} | |
], | |
"source": [ | |
"1/0 and True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "f1f8ad4c", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 55, | |
"id": "fe0c52ba", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "ZeroDivisionError", | |
"evalue": "division by zero", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/2638778418.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" | |
] | |
} | |
], | |
"source": [ | |
"1/0 or True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "4d7fa204", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 56, | |
"id": "802ef4c1", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "ZeroDivisionError", | |
"evalue": "division by zero", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/812870342.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mFalse\u001b[0m \u001b[0;32mor\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m/\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero" | |
] | |
} | |
], | |
"source": [ | |
"False or 1/0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "46c0f1b6", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 57, | |
"id": "50098ff2", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"False" | |
] | |
}, | |
"execution_count": 57, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"False and 1/0" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "f5b0086f", | |
"metadata": {}, | |
"source": [ | |
"http://docs.python.org/library/stdtypes.html#boolean-operations-and-or-not" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "73bca46b", | |
"metadata": {}, | |
"source": [ | |
"## python boolean short-circuit" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "d2e7561e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "b34b657d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "eae4f7c9", | |
"metadata": {}, | |
"source": [ | |
"## trả ngay kết quả khi quyết định" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "1623d4d3", | |
"metadata": {}, | |
"source": [ | |
"- and dừng lại khi gặp False\n", | |
"- or dừng lại khi gặp True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "513a28bf", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a255d11b", | |
"metadata": {}, | |
"source": [ | |
"## secret" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 58, | |
"id": "5cac5374", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2" | |
] | |
}, | |
"execution_count": 58, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True + True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 59, | |
"id": "60647efc", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"3" | |
] | |
}, | |
"execution_count": 59, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True + True + True" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 60, | |
"id": "649814db", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 60, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"True == 1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 61, | |
"id": "a3fbba88", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 61, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"False == 0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "955529fa", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 62, | |
"id": "d7f23ff7", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"x = 5" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 63, | |
"id": "dfa7d629", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"y = 7" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 64, | |
"id": "5a9585a7", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"z = x + y" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 65, | |
"id": "bc8a205a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"12" | |
] | |
}, | |
"execution_count": 65, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"z" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "0ec6a258", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b4be334a", | |
"metadata": {}, | |
"source": [ | |
"## list - Array in Python" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 66, | |
"id": "d477f269", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs = [1,2,3]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 67, | |
"id": "58b0914a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"list" | |
] | |
}, | |
"execution_count": 67, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"type(xs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 71, | |
"id": "220b1108", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ys = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,\n", | |
" 1,1,1,1,1,1,1,1,1,1,1,1,\n", | |
" 1,1,1,1,1,1,1,1,1,1,\n", | |
" 1,1,1,1,1,1,\n", | |
" 1,1]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "28ea43bf", | |
"metadata": {}, | |
"source": [ | |
"## len - length" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 73, | |
"id": "4e798b17", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"50" | |
] | |
}, | |
"execution_count": 73, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"len(ys)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 74, | |
"id": "eb9cb292", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"0" | |
] | |
}, | |
"execution_count": 74, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"len([])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "472b0e08", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 75, | |
"id": "c49ef0fc", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ns = [1,2,3,4,5,6,7,8,9,10]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 76, | |
"id": "2de4a1f5", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"55" | |
] | |
}, | |
"execution_count": 76, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sum(ns)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "1a3bf3b1", | |
"metadata": {}, | |
"source": [ | |
"## tổng 7 đến70" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 79, | |
"id": "c12f04ae", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ns = [7,8,9,\n", | |
" 10,11,12,13,14,15,16,17,18,19,\n", | |
" 20,21,22,23,24,25,26,27,28,29,\n", | |
" 30,31,32,33,34,35,36,37,38,39,\n", | |
" 40,41,42,43,44,45,46,47,48,49,\n", | |
" 50,51,52,53,54,55,56,57,58,59,\n", | |
" 60,61,62,63,64,65,66,67,68,69,\n", | |
" 70]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "846b12d4", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 80, | |
"id": "de7bd467", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2464" | |
] | |
}, | |
"execution_count": 80, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sum(ns)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 82, | |
"id": "5b1e14e3", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"123\n" | |
] | |
} | |
], | |
"source": [ | |
"print(123)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 85, | |
"id": "222d5d36", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ns = list(range(7, 71))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 87, | |
"id": "a4420935", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"2464" | |
] | |
}, | |
"execution_count": 87, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sum(ns)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 86, | |
"id": "479f0457", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(ns)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "7dfb3c11", | |
"metadata": {}, | |
"source": [ | |
"### range [7, 71) - nửa đoạn - không chứa 71" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 90, | |
"id": "93dee24c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"500500" | |
] | |
}, | |
"execution_count": 90, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sum(list(range(1, 1001)))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "4f0f17d8", | |
"metadata": {}, | |
"source": [ | |
"## BTVN: tính đến 1 tỷ theo cách trên ?" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 91, | |
"id": "f78516ca", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ns = [21,22,23,24]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "adec644a", | |
"metadata": {}, | |
"source": [ | |
"## indexing " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 98, | |
"id": "c9bf4613", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"21" | |
] | |
}, | |
"execution_count": 98, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[0] # truy cap vao index 0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 94, | |
"id": "fe71360a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"22" | |
] | |
}, | |
"execution_count": 94, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 95, | |
"id": "b1e10b0b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"23" | |
] | |
}, | |
"execution_count": 95, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[2]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 96, | |
"id": "10990239", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"24" | |
] | |
}, | |
"execution_count": 96, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[3]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 97, | |
"id": "9639a3b5", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "IndexError", | |
"evalue": "list index out of range", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/97245302.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mns\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mIndexError\u001b[0m: list index out of range" | |
] | |
} | |
], | |
"source": [ | |
"ns[4]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 99, | |
"id": "860b14fa", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ns = list(range(27, 1023))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 100, | |
"id": "1d45f939", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1022" | |
] | |
}, | |
"execution_count": 100, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[len(ns)-1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 101, | |
"id": "5a0f95ea", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1021" | |
] | |
}, | |
"execution_count": 101, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[len(ns)-2]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 102, | |
"id": "9aefe427", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1020" | |
] | |
}, | |
"execution_count": 102, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[len(ns)-3]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "a5fc8b15", | |
"metadata": {}, | |
"source": [ | |
"## negative index" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 103, | |
"id": "c6ced48a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1022" | |
] | |
}, | |
"execution_count": 103, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[-1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 104, | |
"id": "b50a5952", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"1021" | |
] | |
}, | |
"execution_count": 104, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[-2]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "53941c23", | |
"metadata": {}, | |
"source": [ | |
"## nhiều" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 106, | |
"id": "8aef614d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[27, 28, 29]" | |
] | |
}, | |
"execution_count": 106, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"[ns[0], ns[1], ns[2]]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "18ced494", | |
"metadata": {}, | |
"source": [ | |
"## slicing - trả về 1 tập con của list " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 107, | |
"id": "ffa988cc", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[27, 28, 29]" | |
] | |
}, | |
"execution_count": 107, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[0:3]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 113, | |
"id": "dfa5aa33", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[3, 4, 5]" | |
] | |
}, | |
"execution_count": 113, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[:3]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 108, | |
"id": "fefe140f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[27, 28, 29, 30, 31]" | |
] | |
}, | |
"execution_count": 108, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[0:5]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 114, | |
"id": "f388a37b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[3, 4, 5]" | |
] | |
}, | |
"execution_count": 114, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[:5]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 110, | |
"id": "8eb1f26f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[32, 33, 34, 35, 36]" | |
] | |
}, | |
"execution_count": 110, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[5:10]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 109, | |
"id": "662e91ca", | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[1020, 1021, 1022]" | |
] | |
}, | |
"execution_count": 109, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[len(ns)-3:len(ns)]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "059b1565", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "0cab6e5e", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 111, | |
"id": "10c7729a", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ns = [3,4,5]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 117, | |
"id": "6be1fdb7", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 117, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[len(ns)-2:len(ns)] == ns[-2:]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 118, | |
"id": "095ab9eb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[5]" | |
] | |
}, | |
"execution_count": 118, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[2:]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "28020c99", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 112, | |
"id": "1e090f6e", | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[]" | |
] | |
}, | |
"execution_count": 112, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ns[7:10]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "6c2f6615", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 119, | |
"id": "b773ee83", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs = list(range(20, 39))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b3aebafc", | |
"metadata": {}, | |
"source": [ | |
"5 phan tu dau tien" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 120, | |
"id": "887f63dc", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[20, 21, 22, 23, 24]" | |
] | |
}, | |
"execution_count": 120, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[:5]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "85848366", | |
"metadata": {}, | |
"source": [ | |
"5 phan tu cuoi cung" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 122, | |
"id": "e1cb92c0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[34, 35, 36, 37, 38]" | |
] | |
}, | |
"execution_count": 122, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[-5:]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "6903ddd4", | |
"metadata": {}, | |
"source": [ | |
"## [] - empty list" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 123, | |
"id": "993226d1", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs = list(range(10, 25))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 124, | |
"id": "6954173a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]" | |
] | |
}, | |
"execution_count": 124, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "9b77d8cf", | |
"metadata": {}, | |
"source": [ | |
"## SLICE[START:STOP:STEP]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 125, | |
"id": "c5fd8f26", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[10, 13, 16, 19, 22]" | |
] | |
}, | |
"execution_count": 125, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[0:len(xs):3]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 126, | |
"id": "8e2126bf", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[10, 13, 16, 19, 22]" | |
] | |
}, | |
"execution_count": 126, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[::3]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "b8b106ec", | |
"metadata": {}, | |
"source": [ | |
"## tạo 1 bản copy (shallow)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 127, | |
"id": "bbf2da34", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]" | |
] | |
}, | |
"execution_count": 127, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[::]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "c7a2ea93", | |
"metadata": {}, | |
"source": [ | |
"## reverse a list" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 128, | |
"id": "73bf1b7b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]" | |
] | |
}, | |
"execution_count": 128, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[::-1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "93076f10", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "e33e174b", | |
"metadata": {}, | |
"source": [ | |
"## tính tổng các số nhỏ hơn 1000 chia hết cho 3 hoặc 5" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 129, | |
"id": "7e7d992b", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"h = list(range(0, 1000))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 131, | |
"id": "05e714da", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"233168" | |
] | |
}, | |
"execution_count": 131, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sum(h[::3]) + sum(h[::5]) - sum(h[::15])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "eca898b2", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "7464bf5e", | |
"metadata": {}, | |
"source": [ | |
"## list có thể chứa MỌI THỨ" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 141, | |
"id": "f7efb472", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs = [2,3,4]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "5f19f782", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 143, | |
"id": "7480c902", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[2, 3, 4, 5, 6]" | |
] | |
}, | |
"execution_count": 143, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"[2,3,4] + [5,6]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 144, | |
"id": "b5fa622d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "TypeError", | |
"evalue": "unsupported operand type(s) for -: 'list' and 'list'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/15974292.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m5\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m6\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'list' and 'list'" | |
] | |
} | |
], | |
"source": [ | |
"[2,3,4] - [5,6]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 145, | |
"id": "ec5a29a0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "TypeError", | |
"evalue": "can't multiply sequence by non-int of type 'list'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m/tmp/ipykernel_63230/2016437751.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;34m[\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[0;31mTypeError\u001b[0m: can't multiply sequence by non-int of type 'list'" | |
] | |
} | |
], | |
"source": [ | |
"[2,3,4] * [3,4]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 147, | |
"id": "5ef4648f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"True" | |
] | |
}, | |
"execution_count": 147, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"2 * 3 == 2 + 2 + 2 == 3 + 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "4e5a7227", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 148, | |
"id": "a0109745", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[2, 3, 4, 2, 3, 4]" | |
] | |
}, | |
"execution_count": 148, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"[2,3,4] * 2" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 149, | |
"id": "17af232d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]" | |
] | |
}, | |
"execution_count": 149, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"[0] * 10" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 150, | |
"id": "56515505", | |
"metadata": { | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[2, 3, 4]" | |
] | |
}, | |
"execution_count": 150, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "da2208b5", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "668ab3f7", | |
"metadata": {}, | |
"source": [ | |
"## list methods" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 151, | |
"id": "a85dc9a3", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs.append(5)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 152, | |
"id": "9289eb6c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[2, 3, 4, 5]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(xs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "2f369fbb", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "bc7b7d7f", | |
"metadata": {}, | |
"source": [ | |
"### append - thêm vào cuối " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 153, | |
"id": "b5746745", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs.append([5,6,7])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 154, | |
"id": "b217fb93", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"[2, 3, 4, 5, [5, 6, 7]]\n" | |
] | |
} | |
], | |
"source": [ | |
"print(xs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 155, | |
"id": "abf4858e", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"5" | |
] | |
}, | |
"execution_count": 155, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"len(xs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 156, | |
"id": "b9ff9a53", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[2, 3, 4, 5, [5, 6, 7]]" | |
] | |
}, | |
"execution_count": 156, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 159, | |
"id": "1edd94a4", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[5, 6, 7]" | |
] | |
}, | |
"execution_count": 159, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[-1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 160, | |
"id": "c4c312a0", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"6" | |
] | |
}, | |
"execution_count": 160, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs[-1][1]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 161, | |
"id": "d3d5eeaf", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[2, 3, 4, 5, [5, 6, 7]]" | |
] | |
}, | |
"execution_count": 161, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "93f91dd6", | |
"metadata": {}, | |
"source": [ | |
"## insert(index, object)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 162, | |
"id": "e9ef05ba", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs.insert(0, 1000)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 163, | |
"id": "0eb893b3", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[1000, 2, 3, 4, 5, [5, 6, 7]]" | |
] | |
}, | |
"execution_count": 163, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 164, | |
"id": "d874512d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs.insert(4, 8)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 165, | |
"id": "a4b0e9b1", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[1000, 2, 3, 4, 8, 5, [5, 6, 7]]" | |
] | |
}, | |
"execution_count": 165, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 166, | |
"id": "b354c830", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs.insert(len(xs), 999)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 167, | |
"id": "caa2e076", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[1000, 2, 3, 4, 8, 5, [5, 6, 7], 999]" | |
] | |
}, | |
"execution_count": 167, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 168, | |
"id": "d027f50d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs.insert(1234, 888)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 169, | |
"id": "72eda27b", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[1000, 2, 3, 4, 8, 5, [5, 6, 7], 999, 888]" | |
] | |
}, | |
"execution_count": 169, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"xs" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "8d8f058d", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"xs." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "c649aa43", | |
"metadata": {}, | |
"source": [ | |
"## list co 11 methods" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 170, | |
"id": "27f1d8d2", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Help on list object:\n", | |
"\n", | |
"class list(object)\n", | |
" | list(iterable=(), /)\n", | |
" | \n", | |
" | Built-in mutable sequence.\n", | |
" | \n", | |
" | If no argument is given, the constructor creates a new empty list.\n", | |
" | The argument must be an iterable if specified.\n", | |
" | \n", | |
" | Methods defined here:\n", | |
" | \n", | |
" | __add__(self, value, /)\n", | |
" | Return self+value.\n", | |
" | \n", | |
" | __contains__(self, key, /)\n", | |
" | Return key in self.\n", | |
" | \n", | |
" | __delitem__(self, key, /)\n", | |
" | Delete self[key].\n", | |
" | \n", | |
" | __eq__(self, value, /)\n", | |
" | Return self==value.\n", | |
" | \n", | |
" | __ge__(self, value, /)\n", | |
" | Return self>=value.\n", | |
" | \n", | |
" | __getattribute__(self, name, /)\n", | |
" | Return getattr(self, name).\n", | |
" | \n", | |
" | __getitem__(...)\n", | |
" | x.__getitem__(y) <==> x[y]\n", | |
" | \n", | |
" | __gt__(self, value, /)\n", | |
" | Return self>value.\n", | |
" | \n", | |
" | __iadd__(self, value, /)\n", | |
" | Implement self+=value.\n", | |
" | \n", | |
" | __imul__(self, value, /)\n", | |
" | Implement self*=value.\n", | |
" | \n", | |
" | __init__(self, /, *args, **kwargs)\n", | |
" | Initialize self. See help(type(self)) for accurate signature.\n", | |
" | \n", | |
" | __iter__(self, /)\n", | |
" | Implement iter(self).\n", | |
" | \n", | |
" | __le__(self, value, /)\n", | |
" | Return self<=value.\n", | |
" | \n", | |
" | __len__(self, /)\n", | |
" | Return len(self).\n", | |
" | \n", | |
" | __lt__(self, value, /)\n", | |
" | Return self<value.\n", | |
" | \n", | |
" | __mul__(self, value, /)\n", | |
" | Return self*value.\n", | |
" | \n", | |
" | __ne__(self, value, /)\n", | |
" | Return self!=value.\n", | |
" | \n", | |
" | __repr__(self, /)\n", | |
" | Return repr(self).\n", | |
" | \n", | |
" | __reversed__(self, /)\n", | |
" | Return a reverse iterator over the list.\n", | |
" | \n", | |
" | __rmul__(self, value, /)\n", | |
" | Return value*self.\n", | |
" | \n", | |
" | __setitem__(self, key, value, /)\n", | |
" | Set self[key] to value.\n", | |
" | \n", | |
" | __sizeof__(self, /)\n", | |
" | Return the size of the list in memory, in bytes.\n", | |
" | \n", | |
" | append(self, object, /)\n", | |
" | Append object to the end of the list.\n", | |
" | \n", | |
" | clear(self, /)\n", | |
" | Remove all items from list.\n", | |
" | \n", | |
" | copy(self, /)\n", | |
" | Return a shallow copy of the list.\n", | |
" | \n", | |
" | count(self, value, /)\n", | |
" | Return number of occurrences of value.\n", | |
" | \n", | |
" | extend(self, iterable, /)\n", | |
" | Extend list by appending elements from the iterable.\n", | |
" | \n", | |
" | index(self, value, start=0, stop=9223372036854775807, /)\n", | |
" | Return first index of value.\n", | |
" | \n", | |
" | Raises ValueError if the value is not present.\n", | |
" | \n", | |
" | insert(self, index, object, /)\n", | |
" | Insert object before index.\n", | |
" | \n", | |
" | pop(self, index=-1, /)\n", | |
" | Remove and return item at index (default last).\n", | |
" | \n", | |
" | Raises IndexError if list is empty or index is out of range.\n", | |
" | \n", | |
" | remove(self, value, /)\n", | |
" | Remove first occurrence of value.\n", | |
" | \n", | |
" | Raises ValueError if the value is not present.\n", | |
" | \n", | |
" | reverse(self, /)\n", | |
" | Reverse *IN PLACE*.\n", | |
" | \n", | |
" | sort(self, /, *, key=None, reverse=False)\n", | |
" | Sort the list in ascending order and return None.\n", | |
" | \n", | |
" | The sort is in-place (i.e. the list itself is modified) and stable (i.e. the\n", | |
" | order of two equal elements is maintained).\n", | |
" | \n", | |
" | If a key function is given, apply it once to each list item and sort them,\n", | |
" | ascending or descending, according to their function values.\n", | |
" | \n", | |
" | The reverse flag can be set to sort in descending order.\n", | |
" | \n", | |
" | ----------------------------------------------------------------------\n", | |
" | Static methods defined here:\n", | |
" | \n", | |
" | __new__(*args, **kwargs) from builtins.type\n", | |
" | Create and return a new object. See help(type) for accurate signature.\n", | |
" | \n", | |
" | ----------------------------------------------------------------------\n", | |
" | Data and other attributes defined here:\n", | |
" | \n", | |
" | __hash__ = None\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"help(xs)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "d8412b88", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "6fa71a99", | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.10" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment