Skip to content

Instantly share code, notes, and snippets.

@hvnsweeting
Created July 6, 2021 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hvnsweeting/58196d9bc39e1f7a27ec8611199ec5ea to your computer and use it in GitHub Desktop.
Save hvnsweeting/58196d9bc39e1f7a27ec8611199ec5ea to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "naughty-arnold",
"metadata": {},
"source": [
"# Pymi.vn - lesson 2"
]
},
{
"cell_type": "markdown",
"id": "virgin-egyptian",
"metadata": {},
"source": [
"- tham gia slack"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "consistent-traveler",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "mighty-television",
"metadata": {},
"source": [
"## bài 1\n",
"- int\n",
"- float\n",
"- các phép toán với số: `+ - * / **`\n",
"- exception\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "homeless-philadelphia",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 // 2"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "emotional-preservation",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2.0"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 / 2"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "sought-electricity",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 // 2"
]
},
{
"cell_type": "markdown",
"id": "major-wagner",
"metadata": {},
"source": [
"## modulo"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "harmful-italian",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 % 2"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "indonesian-check",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5 % 3"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "absolute-launch",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 % 5"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "electronic-beast",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"15 % 7"
]
},
{
"cell_type": "markdown",
"id": "indie-couple",
"metadata": {},
"source": [
"# Giảm kích thước bài toán có tính chất chu kỳ"
]
},
{
"cell_type": "markdown",
"id": "improving-plate",
"metadata": {},
"source": [
"## 2021 - tân sửu"
]
},
{
"cell_type": "markdown",
"id": "peripheral-studio",
"metadata": {},
"source": [
"## 2033 - cái gif_ sửu"
]
},
{
"cell_type": "markdown",
"id": "first-vector",
"metadata": {},
"source": [
"## thiên can - địa chia"
]
},
{
"cell_type": "markdown",
"id": "worldwide-jumping",
"metadata": {},
"source": [
"### Địa chi - 12 con giáp\n",
"- tí sửu dần mão ...\n",
"\n",
"### 10 thiên can \n",
"- canh tân nhâm quý giáp ất bính đinh mậu kỷ"
]
},
{
"cell_type": "markdown",
"id": "enhanced-superior",
"metadata": {},
"source": [
"## 2009 là năm gì?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "arranged-railway",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "afraid-polymer",
"metadata": {},
"source": [
"## năm 1369 là năm gì?"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "superb-weekend",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"652"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d = 2021 - 1369\n",
"d"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "young-abraham",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d % 12"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "sufficient-lender",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"d % 10"
]
},
{
"cell_type": "markdown",
"id": "genuine-cotton",
"metadata": {},
"source": [
"https://canchi.pymi.vn/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "strong-calvin",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 14,
"id": "hungry-sterling",
"metadata": {},
"outputs": [],
"source": [
"c = 3 + 2j \n",
"d = 5 + 5j"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "pregnant-elder",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"complex"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(c)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "downtown-final",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(8+7j)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"c + d"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "exciting-costume",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "developed-woman",
"metadata": {},
"source": [
"## boolean Pronunciation /ˈbuːlɪən/ "
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "wireless-indie",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"3 < 4 "
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "chronic-tenant",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"3 > 4"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "varied-package",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bool"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(3 < 4)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "emotional-guatemala",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bool"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(True)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "certain-vacuum",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bool"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(False)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "deluxe-painting",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"3 <= 3"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "integrated-detail",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"3 >= 3"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "extreme-offering",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 2 == 3"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "humanitarian-demonstration",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 1 != 3"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "fifteen-cisco",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
".1 + .1 + .1 != .3"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "other-tracy",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 28,
"id": "permanent-green",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"2 < 3 < 4"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "emerging-falls",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"4 < 3 < 5"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "finite-experiment",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 25,
"id": "worst-environment",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "cannot assign to operator (<ipython-input-25-8ca2c3fac6f3>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-25-8ca2c3fac6f3>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m 1 + 2 = 3\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m cannot assign to operator\n"
]
}
],
"source": [
"1 + 2 = 3"
]
},
{
"cell_type": "markdown",
"id": "medical-ranch",
"metadata": {},
"source": [
"## NOT "
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "labeled-asset",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not True "
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "driven-navigator",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not False "
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "ordinary-appeal",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not not True"
]
},
{
"cell_type": "markdown",
"id": "treated-threat",
"metadata": {},
"source": [
"## don't do this"
]
},
{
"cell_type": "code",
"execution_count": 33,
"id": "chronic-budget",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not True == False"
]
},
{
"cell_type": "markdown",
"id": "exposed-showcase",
"metadata": {},
"source": [
"## do this"
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "martial-miami",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not True is False "
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "possible-negotiation",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not False is True "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "embedded-energy",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "downtown-attention",
"metadata": {},
"source": [
"## and "
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "retained-pharmacy",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True and True "
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "banner-drove",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True and False "
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "incredible-substitute",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False and True "
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "temporal-raising",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False and False "
]
},
{
"cell_type": "markdown",
"id": "loved-navigation",
"metadata": {},
"source": [
"## or"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "nuclear-third",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or True "
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "everyday-welsh",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or False"
]
},
{
"cell_type": "code",
"execution_count": 42,
"id": "broad-worst",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False or True"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "rotary-marathon",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False or False"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "traditional-convention",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 44,
"id": "religious-apparatus",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or 1/0"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "recent-terrorist",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False and 1/0"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "beneficial-grenada",
"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<ipython-input-47-998809ef73d8>\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": 46,
"id": "difficult-observer",
"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<ipython-input-46-17c98249f050>\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": 45,
"id": "accredited-angola",
"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<ipython-input-45-094ec76626b6>\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": "markdown",
"id": "oriented-hierarchy",
"metadata": {},
"source": [
"### python short-circuit boolean"
]
},
{
"cell_type": "markdown",
"id": "centered-separation",
"metadata": {},
"source": [
"### Python boolean sẽ dừng lại sớm nhất ngay khi \n",
"### quyết định được kết quả"
]
},
{
"cell_type": "markdown",
"id": "constant-knitting",
"metadata": {},
"source": [
"### or dừng lại khi thấy True\n",
"### and dừng lại khi thấy False"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "optional-lafayette",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "extensive-invalid",
"metadata": {},
"source": [
"#### BIẾT CHỨ KHÔNG DÙNG"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "smart-jenny",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True + True + True "
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "blond-chorus",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True == 1"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "tropical-facing",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False == 0"
]
},
{
"cell_type": "markdown",
"id": "handy-oakland",
"metadata": {},
"source": [
"https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "facial-visitor",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "distant-bunny",
"metadata": {},
"source": [
"## list"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "clinical-receiver",
"metadata": {},
"outputs": [],
"source": [
"xs = [3,2,1,5,4]"
]
},
{
"cell_type": "code",
"execution_count": 53,
"id": "material-suggestion",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"list"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(xs)"
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "unlikely-nothing",
"metadata": {},
"outputs": [],
"source": [
"ks = [1, 2.0, True, 5.6]"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "stuck-field",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"list"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(ks)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"id": "expanded-weapon",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[3, 2, 1, 5, 4], [1, 2.0, True, 5.6]]"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"big = [xs, ks]\n",
"big"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "tribal-engine",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(big)"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "automatic-range",
"metadata": {},
"outputs": [],
"source": [
"empty = []"
]
},
{
"cell_type": "code",
"execution_count": 58,
"id": "continental-hollywood",
"metadata": {},
"outputs": [],
"source": [
"ns = [3,2,4]\n"
]
},
{
"cell_type": "code",
"execution_count": 59,
"id": "rental-davis",
"metadata": {},
"outputs": [],
"source": [
"lst = [1,2,1,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,]"
]
},
{
"cell_type": "markdown",
"id": "opened-jones",
"metadata": {},
"source": [
"## len - length"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "architectural-complexity",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(lst)"
]
},
{
"cell_type": "code",
"execution_count": 61,
"id": "frank-thailand",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(empty)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aware-bristol",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 63,
"id": "internal-geneva",
"metadata": {},
"outputs": [],
"source": [
"xs = [3,2,1,5]"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "touched-frontier",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "naval-chorus",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(xs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "understood-parent",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 69,
"id": "drawn-curtis",
"metadata": {},
"outputs": [],
"source": [
"ns = [1,2,3,4,5,6,7,8,9,10,\n",
" 11,12,13,14,15,16,17,18,19,20,\n",
" 21,22,23,24,25,26,27,28,29,30,\n",
" 31,32,33,34,35,36,37,38,39,40,\n",
" 41,42,43,44,45,46,47,48,49,50,\n",
" 51,52,53,54,55,56,57,58,59,60,\n",
" 61,62,63,64,65,66,67,68,69,70,\n",
" 71,72,73,74,75,76,77,78,79,80,\n",
" 81,82,83,84,85,86,87,88,89,90,\n",
" 91,92,93,94,95,96,97,98,99]"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "attached-stations",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4950"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(ns)"
]
},
{
"cell_type": "markdown",
"id": "successful-brass",
"metadata": {},
"source": [
"## sinh ra dãy int từ 1 đến TRƯỚC 10"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "important-stroke",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9]"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(range(1, 10))"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "middle-fitness",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"4950"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns = list(range(1, 100))\n",
"sum(ns)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "injured-tennessee",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 74,
"id": "nominated-corpus",
"metadata": {},
"outputs": [],
"source": [
"xs = [3,2,1,5]"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "advisory-instruction",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs"
]
},
{
"cell_type": "markdown",
"id": "inclusive-advantage",
"metadata": {},
"source": [
"### truy cập phần tử của list"
]
},
{
"cell_type": "markdown",
"id": "related-cylinder",
"metadata": {},
"source": [
"## số 0 là index "
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "ambient-element",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[0]"
]
},
{
"cell_type": "code",
"execution_count": 78,
"id": "revolutionary-passenger",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[1]"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "overall-secondary",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[2]"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "muslim-entertainment",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[3]"
]
},
{
"cell_type": "code",
"execution_count": 81,
"id": "capable-waste",
"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<ipython-input-81-44b2225a832d>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mxs\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": [
"xs[4]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "saved-intro",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 85,
"id": "three-heating",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"99"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[len(ns)-1]"
]
},
{
"cell_type": "code",
"execution_count": 88,
"id": "alpine-miller",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"99"
]
},
"execution_count": 88,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-1]"
]
},
{
"cell_type": "markdown",
"id": "convertible-exploration",
"metadata": {},
"source": [
"### negative index"
]
},
{
"cell_type": "code",
"execution_count": 89,
"id": "presidential-narrow",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 89,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "characteristic-specialist",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 86,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[len(xs)-1]"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "intellectual-ocean",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 87,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[-1]"
]
},
{
"cell_type": "code",
"execution_count": 90,
"id": "occupied-renewal",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 90,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[-4]"
]
},
{
"cell_type": "code",
"execution_count": 91,
"id": "limiting-harrison",
"metadata": {
"scrolled": true
},
"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<ipython-input-91-0c502a6da7fc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mxs\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m5\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": [
"xs[-5]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "likely-county",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 92,
"id": "fifty-annotation",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 92,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "noted-script",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1]"
]
},
"execution_count": 93,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ts = [xs[0], xs[1], xs[2]]\n",
"ts"
]
},
{
"cell_type": "markdown",
"id": "stretch-circus",
"metadata": {},
"source": [
"## slicing (slice)"
]
},
{
"cell_type": "code",
"execution_count": 95,
"id": "statistical-father",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1]"
]
},
"execution_count": 95,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[0:3]"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "manual-rouge",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1]"
]
},
"execution_count": 100,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[:3]"
]
},
{
"cell_type": "code",
"execution_count": 96,
"id": "amber-custody",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
]
},
"execution_count": 96,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[0:10]"
]
},
{
"cell_type": "code",
"execution_count": 101,
"id": "atmospheric-cargo",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"
]
},
"execution_count": 101,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[:10]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "manufactured-tiffany",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 99,
"id": "missing-fields",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 99,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs"
]
},
{
"cell_type": "code",
"execution_count": 98,
"id": "divine-track",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 5]"
]
},
"execution_count": 98,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[xs[-2], xs[-1]]"
]
},
{
"cell_type": "code",
"execution_count": 104,
"id": "bizarre-ready",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 5]"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[-2:len(xs)]"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "remarkable-angel",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 5]"
]
},
"execution_count": 105,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[-2:]"
]
},
{
"cell_type": "code",
"execution_count": 106,
"id": "heated-soviet",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[90, 91, 92, 93, 94, 95, 96, 97, 98, 99]"
]
},
"execution_count": 106,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-10:]"
]
},
{
"cell_type": "code",
"execution_count": 108,
"id": "demanding-mailman",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2]"
]
},
"execution_count": 108,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[:2]"
]
},
{
"cell_type": "code",
"execution_count": 109,
"id": "utility-burns",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[98, 99]"
]
},
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-2:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "unavailable-heart",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "successful-attendance",
"metadata": {},
"source": [
"## tạo 1 bản (shallow) copy"
]
},
{
"cell_type": "code",
"execution_count": 111,
"id": "municipal-competition",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 111,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "foreign-alexander",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 112,
"id": "transparent-lithuania",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 112,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs"
]
},
{
"cell_type": "code",
"execution_count": 113,
"id": "chubby-brave",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 2, 1, 5]"
]
},
"execution_count": 113,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[0:10]"
]
},
{
"cell_type": "code",
"execution_count": 114,
"id": "demographic-auction",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 114,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[10:20]"
]
},
{
"cell_type": "code",
"execution_count": 115,
"id": "extreme-riverside",
"metadata": {},
"outputs": [],
"source": [
"ns = [4,5,6,7,8]"
]
},
{
"cell_type": "code",
"execution_count": 116,
"id": "golden-procurement",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[4, 5, 6, 7, 8]"
]
},
"execution_count": 116,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns"
]
},
{
"cell_type": "markdown",
"id": "relative-delaware",
"metadata": {},
"source": [
"## slice[START:STOP:STEP]"
]
},
{
"cell_type": "code",
"execution_count": 121,
"id": "innocent-output",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[4, 5, 6, 7, 8]"
]
},
"execution_count": 121,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns"
]
},
{
"cell_type": "code",
"execution_count": 120,
"id": "framed-packet",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[4, 6, 8]"
]
},
"execution_count": 120,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[0:len(ns):2]"
]
},
{
"cell_type": "code",
"execution_count": 119,
"id": "adaptive-characteristic",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[4, 6, 8]"
]
},
"execution_count": 119,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[::2]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "composed-affiliate",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 123,
"id": "radical-street",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[5, 7]"
]
},
"execution_count": 123,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[1::2]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fifteen-thesaurus",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "accessory-genome",
"metadata": {},
"source": [
"### đảo ngược list "
]
},
{
"cell_type": "code",
"execution_count": 126,
"id": "lovely-teach",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[8, 7, 6, 5, 4]"
]
},
"execution_count": 126,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[::-1]"
]
},
{
"cell_type": "markdown",
"id": "weighted-ferry",
"metadata": {},
"source": [
"### x -> số nhiều thêm s -> xs "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "utility-attraction",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "governmental-house",
"metadata": {},
"source": [
"## Bài tập https://projecteuler.net/"
]
},
{
"cell_type": "markdown",
"id": "breathing-analyst",
"metadata": {},
"source": [
"https://projecteuler.net/problem=1"
]
},
{
"cell_type": "markdown",
"id": "circular-moses",
"metadata": {},
"source": [
"PE01: Multiples of 3 and 5\n",
"\n",
"Problem 1\n",
"\n",
"If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.\n",
"\n",
"Find the sum of all the multiples of 3 or 5 below 1000.\n"
]
},
{
"cell_type": "markdown",
"id": "christian-manor",
"metadata": {},
"source": [
"### tính tổng các bội của 3 hoặc 5 nhỏ hơn 1000"
]
},
{
"cell_type": "markdown",
"id": "raising-water",
"metadata": {},
"source": [
"## Vào channel Slack này pymihn2107-pub"
]
},
{
"cell_type": "code",
"execution_count": 127,
"id": "industrial-recovery",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"233168"
]
},
"execution_count": 127,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(i for i in range(1, 1000) if i % 3 == 0 or i % 5 == 0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "recreational-argument",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 138,
"id": "outstanding-receipt",
"metadata": {},
"outputs": [],
"source": [
"x3 = list(range(1000))[::3]"
]
},
{
"cell_type": "code",
"execution_count": 139,
"id": "international-saskatchewan",
"metadata": {},
"outputs": [],
"source": [
"x5 = list(range(1000))[::5]"
]
},
{
"cell_type": "code",
"execution_count": 140,
"id": "another-minute",
"metadata": {},
"outputs": [],
"source": [
"x15 = list(range(1000))[::15]"
]
},
{
"cell_type": "code",
"execution_count": 141,
"id": "broad-lambda",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"233168"
]
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(x3) + sum(x5) - sum(x15)"
]
},
{
"cell_type": "markdown",
"id": "trained-carol",
"metadata": {},
"source": [
"https://docs.python.org/3/tutorial/introduction.html#lists"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "hidden-rebel",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "industrial-reflection",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "detailed-deposit",
"metadata": {},
"source": [
"## nested list"
]
},
{
"cell_type": "code",
"execution_count": 142,
"id": "introductory-cincinnati",
"metadata": {},
"outputs": [],
"source": [
"nested = [[22,11,33], [2], [4,5,6]]"
]
},
{
"cell_type": "code",
"execution_count": 144,
"id": "chief-syracuse",
"metadata": {},
"outputs": [],
"source": [
"e1 = nested[0]"
]
},
{
"cell_type": "code",
"execution_count": 146,
"id": "living-insider",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"33"
]
},
"execution_count": 146,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"e1[-1]"
]
},
{
"cell_type": "code",
"execution_count": 149,
"id": "hourly-sunset",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"33"
]
},
"execution_count": 149,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"nested[0][-1]"
]
},
{
"cell_type": "markdown",
"id": "modified-hungarian",
"metadata": {},
"source": [
"## assign item"
]
},
{
"cell_type": "code",
"execution_count": 150,
"id": "frank-rhythm",
"metadata": {},
"outputs": [],
"source": [
"xs = [2,4,3,1]"
]
},
{
"cell_type": "code",
"execution_count": 154,
"id": "speaking-justice",
"metadata": {},
"outputs": [],
"source": [
"xs[-2] = 300"
]
},
{
"cell_type": "code",
"execution_count": 155,
"id": "sustainable-contractor",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[2, 4, 300, 1]"
]
},
"execution_count": 155,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "anticipated-sugar",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "harmful-butter",
"metadata": {},
"source": [
"## add , * list"
]
},
{
"cell_type": "code",
"execution_count": 157,
"id": "appreciated-vacation",
"metadata": {},
"outputs": [],
"source": [
"xs = [1,2,3]\n",
"ys = [4,5,6,7]"
]
},
{
"cell_type": "code",
"execution_count": 158,
"id": "noted-relevance",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5, 6, 7]"
]
},
"execution_count": 158,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs + ys "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "owned-nepal",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 160,
"id": "vital-insurance",
"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<ipython-input-160-920510fad5a7>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mxs\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mys\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": [
"xs - ys"
]
},
{
"cell_type": "code",
"execution_count": 162,
"id": "legendary-brick",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 1, 2, 3, 1, 2, 3]"
]
},
"execution_count": 162,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs * 3"
]
},
{
"cell_type": "code",
"execution_count": 163,
"id": "adjustable-particular",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]"
]
},
"execution_count": 163,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[1] * 10"
]
},
{
"cell_type": "markdown",
"id": "empty-motivation",
"metadata": {},
"source": [
"## str"
]
},
{
"cell_type": "code",
"execution_count": 164,
"id": "continuing-publisher",
"metadata": {},
"outputs": [],
"source": [
"s = 'Python is no 1'"
]
},
{
"cell_type": "code",
"execution_count": 165,
"id": "guilty-wheel",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Python is no 1\n"
]
}
],
"source": [
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 166,
"id": "structured-yellow",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello PyMIERs\n"
]
}
],
"source": [
"print('Hello PyMIERs')"
]
},
{
"cell_type": "code",
"execution_count": 167,
"id": "killing-manual",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"str"
]
},
"execution_count": 167,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(s)"
]
},
{
"cell_type": "markdown",
"id": "common-class",
"metadata": {},
"source": [
"## `'` - single quote"
]
},
{
"cell_type": "markdown",
"id": "associate-worker",
"metadata": {},
"source": [
"`\"` - double quotes"
]
},
{
"cell_type": "markdown",
"id": "incorporated-accused",
"metadata": {},
"source": [
"`\"\"\" - triple quotes`"
]
},
{
"cell_type": "code",
"execution_count": 169,
"id": "approved-uniform",
"metadata": {},
"outputs": [],
"source": [
"s1 = 'meo meo'\n",
"s2 = \"meo meo\""
]
},
{
"cell_type": "code",
"execution_count": 171,
"id": "accurate-finland",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 171,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s1 == s2"
]
},
{
"cell_type": "code",
"execution_count": 172,
"id": "former-strap",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'meo meo'"
]
},
"execution_count": 172,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s1"
]
},
{
"cell_type": "code",
"execution_count": 173,
"id": "generous-flexibility",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7"
]
},
"execution_count": 173,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(s1)"
]
},
{
"cell_type": "code",
"execution_count": 174,
"id": "appropriate-watershed",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'m'"
]
},
"execution_count": 174,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s1[0]"
]
},
{
"cell_type": "code",
"execution_count": 175,
"id": "ordinary-grave",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'o'"
]
},
"execution_count": 175,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s1[-1]"
]
},
{
"cell_type": "code",
"execution_count": 176,
"id": "frozen-township",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'meo'"
]
},
"execution_count": 176,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s1[:3]"
]
},
{
"cell_type": "code",
"execution_count": 178,
"id": "thousand-employer",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'meo'"
]
},
"execution_count": 178,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s1[-3:]"
]
},
{
"cell_type": "code",
"execution_count": 180,
"id": "valuable-cookbook",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'oem oem'"
]
},
"execution_count": 180,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s[::-1]"
]
},
{
"cell_type": "code",
"execution_count": 182,
"id": "documented-colombia",
"metadata": {},
"outputs": [],
"source": [
"s3 = 'Python '"
]
},
{
"cell_type": "code",
"execution_count": 183,
"id": "indie-novel",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'meo meo'"
]
},
"execution_count": 183,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s"
]
},
{
"cell_type": "code",
"execution_count": 184,
"id": "piano-birmingham",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'meo meoPython '"
]
},
"execution_count": 184,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s + s3"
]
},
{
"cell_type": "code",
"execution_count": 185,
"id": "quick-judge",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'meo meomeo meomeo meo'"
]
},
"execution_count": 185,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s * 3"
]
},
{
"cell_type": "code",
"execution_count": 186,
"id": "developmental-combining",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'====================**********===================='"
]
},
"execution_count": 186,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"'=' * 20 + '*' * 10 + '=' * 20"
]
},
{
"cell_type": "markdown",
"id": "potential-outside",
"metadata": {},
"source": [
"## I'm Pymier"
]
},
{
"cell_type": "code",
"execution_count": 189,
"id": "continued-scale",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-189-fbd2d09cdb6a>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-189-fbd2d09cdb6a>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m s = 'I'm Pymier'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
"source": [
"s = 'I'm Pymier'"
]
},
{
"cell_type": "code",
"execution_count": 190,
"id": "suffering-success",
"metadata": {},
"outputs": [],
"source": [
"s = \"I'm Pymier\""
]
},
{
"cell_type": "code",
"execution_count": 191,
"id": "fitted-oracle",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I'm Pymier\n"
]
}
],
"source": [
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 193,
"id": "floral-royal",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Day la double \" quote \n"
]
}
],
"source": [
"s2 = 'Day la double \" quote '\n",
"print(s2)"
]
},
{
"cell_type": "markdown",
"id": "brilliant-pressing",
"metadata": {},
"source": [
"### use \\' to escape the single quote\n",
"\n",
"https://docs.python.org/3/tutorial/introduction.html#strings"
]
},
{
"cell_type": "code",
"execution_count": 195,
"id": "minus-caribbean",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I'm Pymier\n"
]
}
],
"source": [
"s = 'I\\'m Pymier'\n",
"print(s)"
]
},
{
"cell_type": "markdown",
"id": "placed-baseball",
"metadata": {},
"source": [
"## "
]
},
{
"cell_type": "code",
"execution_count": 196,
"id": "renewable-responsibility",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "EOL while scanning string literal (<ipython-input-196-bfc4ef011b9a>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-196-bfc4ef011b9a>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m tho = 'nếu biết người ấy đã lấy chồng\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m EOL while scanning string literal\n"
]
}
],
"source": [
"tho = 'nếu biết người ấy đã lấy chồng\n",
"em về mua 3 lít bia uống là xong'"
]
},
{
"cell_type": "markdown",
"id": "clinical-sherman",
"metadata": {},
"source": [
"## `\\n` - newline"
]
},
{
"cell_type": "code",
"execution_count": 198,
"id": "foster-chancellor",
"metadata": {},
"outputs": [],
"source": [
"tho = 'nếu biết người ấy đã lấy chồng\\nem về mua 3 lít bia uống là xong'"
]
},
{
"cell_type": "code",
"execution_count": 199,
"id": "blessed-poverty",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"nếu biết người ấy đã lấy chồng\n",
"em về mua 3 lít bia uống là xong\n"
]
}
],
"source": [
"print(tho)"
]
},
{
"cell_type": "code",
"execution_count": 200,
"id": "subject-detroit",
"metadata": {},
"outputs": [],
"source": [
"tho = \"\"\"nếu biết người ấy đã lấy chồng\n",
"em về mua 3 lít bia uống làm xong\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 201,
"id": "infinite-proxy",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"nếu biết người ấy đã lấy chồng\n",
"em về mua 3 lít bia uống làm xong\n"
]
}
],
"source": [
"print(tho)"
]
},
{
"cell_type": "markdown",
"id": "coral-connection",
"metadata": {},
"source": [
"### BTVN: đọc tài liệu trang chủ \n",
"- http://pymi.vn/tutorial/string1/\n",
"- http://pymi.vn/tutorial/naming/\n",
"- http://pymi.vn/tutorial/unicode/\n",
"- Đăng ký một tài khoản Slack tại http://invite.pymi.vn/ để trao đổi / chat chit với các đồng môn, nhận thông báo về lớp."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "approved-spoke",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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