Skip to content

Instantly share code, notes, and snippets.

@hvnsweeting
Created March 12, 2024 14:37
Show Gist options
  • Save hvnsweeting/35696877a56222b8431aa35f6b6d7c36 to your computer and use it in GitHub Desktop.
Save hvnsweeting/35696877a56222b8431aa35f6b6d7c36 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "8cf5d4b5-2a88-4099-a8fe-050baf28ae36",
"metadata": {},
"source": [
"# Python at https://pymi.vn - lesson 2"
]
},
{
"cell_type": "markdown",
"id": "0c761eea-65a4-4c68-892d-918ec62fc6d8",
"metadata": {},
"source": [
"## Comparision"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d0474b23-6bf7-4ec6-8902-2e4127e5e3f3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 < 2"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d70586fb-1455-42a4-af9f-fb6649f389a4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 == 2"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "25ac71e4-a663-4b46-bf58-72e3f643d18c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bool"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(1<2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "200cf2ef-d538-4247-84bc-75e1c3f9f836",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "623dfede-3e01-4fcd-a405-c359440e10eb",
"metadata": {},
"source": [
"## bool - Boolean uk /ˈbuːliən/ us\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "51a9730e-b28f-4560-abed-731a9ccac67f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cf94d194-e0f6-448b-a8bf-8cdf502d5d36",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 == 2"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "4f395f78-948f-4bdc-9e19-df6eb8505917",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bool"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(True)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "31b58630-408b-4b48-ac32-db6d65ad6197",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"bool"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(False)"
]
},
{
"cell_type": "markdown",
"id": "721cb3cc-a477-402f-a93c-82a3986a00f1",
"metadata": {},
"source": [
"### True & False viết HOA chữ cái đầu "
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "d55ff4df-19a5-4cb8-bf74-47382d84005b",
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'true' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[9], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mtrue\u001b[49m\n",
"\u001b[0;31mNameError\u001b[0m: name 'true' is not defined"
]
}
],
"source": [
"true"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "46eea631-d56e-49c4-9d7b-15fcb551e4b2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 10,
"id": "21f81450-26ac-4c8a-8135-236d44ee476c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"-42432"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 + 2 - 345 * 123"
]
},
{
"cell_type": "markdown",
"id": "33e76878-5e54-4bf7-be0d-4996d0630893",
"metadata": {},
"source": [
"### phép toán với boolean"
]
},
{
"cell_type": "markdown",
"id": "164f0321-f2a0-4b66-add3-2a4db04d3905",
"metadata": {},
"source": [
"## 3 phép toán (operator)"
]
},
{
"cell_type": "markdown",
"id": "7ad0be61-63fd-4ee6-8659-88b8cb7f9ad9",
"metadata": {},
"source": [
"### 1 + 2: + operator(phép toán), 1,2 are operand (toán hạng)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa328f4b-b93d-48ca-8c5b-fc8c7336c320",
"metadata": {},
"outputs": [],
"source": [
"True False"
]
},
{
"cell_type": "markdown",
"id": "133a1883-31c4-4a1d-bb66-736fbfe3a60e",
"metadata": {},
"source": [
"## not - phủ định"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "d3e4709f-6eaf-496e-a08a-f42ab0b3b568",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not True "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "41bfce4f-1eb3-44e4-9b55-2bcf99c64aa0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"not False "
]
},
{
"cell_type": "markdown",
"id": "c87f78b7-74be-4fb9-95e1-64cdf337e02c",
"metadata": {},
"source": [
"## and - và "
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "bc0beabb-a129-4c0a-8284-009b92c3857f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True and True"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "f48a7f7f-6652-4f24-a51b-751c3f8fb79c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True and False"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "22f1da62-fb8a-4c15-8655-a1170841a5bf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False and True"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "b1392f98-5108-4bf8-aa1a-5d4d85208adb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False and False "
]
},
{
"cell_type": "markdown",
"id": "2c2edd73-2794-4e9d-9144-17a4868a58ce",
"metadata": {},
"source": [
"## or - hoặc "
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "30ebb4f5-d6a8-41cf-9028-c46d9739df1d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or True"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "60e0337e-89da-434c-9710-aa2a1604db7e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or False"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "66458e51-901b-4e2a-8003-4942b0c69cfe",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False or True"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "aaac413f-402e-43a1-a64d-4d43d1469cb9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False or False # ca 2 cung false"
]
},
{
"cell_type": "markdown",
"id": "4861a7f0-13a7-4778-ab95-0d9c38ad8b34",
"metadata": {},
"source": [
"## Đố rất vui - có thưởng"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "65f462db-ba99-4d74-b539-15877e10658f",
"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)",
"Cell \u001b[0;32mIn[25], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mTrue\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;241;43m1\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\n",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"True and 1/0"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "65e8b992-fb4b-4734-a1e9-e444652b2c51",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or 1/0"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "10159e31-9ecc-441e-beb7-96339a81e163",
"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)",
"Cell \u001b[0;32mIn[28], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mTrue\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;241;43m1\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m \n",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"True and 1/0 "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e77cf3c-490d-4553-bf56-fbe83eae40a0",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 27,
"id": "f897f8d0-cdf5-4de9-a2b8-58b9415f1240",
"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)",
"Cell \u001b[0;32mIn[27], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;241;43m1\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m \n",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"1/0 or True "
]
},
{
"cell_type": "markdown",
"id": "bf6c4652-bc6a-4198-b5e0-215a3c377a9e",
"metadata": {},
"source": [
"https://docs.python.org/3/library/stdtypes.html#boolean-operations-and-or-not"
]
},
{
"cell_type": "markdown",
"id": "c5d1330a-b6d5-43d8-bbd9-dbf3d8c56679",
"metadata": {},
"source": [
"### Boolean: short circuit (ngắn mạch)\n",
"CHỈ TÍNH giá trị tiếp theo nếu CHƯA QUYẾT ĐỊNH ĐƯỢC KẾT QUẢ.\n",
"\n",
"- or: True dừng lại \n",
"- and: gặp False dừng lại "
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "be7e9e0c-0a70-4eff-befd-fa1737a96c4a",
"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)",
"Cell \u001b[0;32mIn[29], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mTrue\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;241;43m1\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m \n",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"True and 1/0 "
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "ec50c1bb-ab5a-46fe-a932-8a954794652b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True or 1/0 "
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "3102327c-c0e7-458c-9d8e-99934e132338",
"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)",
"Cell \u001b[0;32mIn[31], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mFalse\u001b[39;00m \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;241;43m1\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m \n",
"\u001b[0;31mZeroDivisionError\u001b[0m: division by zero"
]
}
],
"source": [
"False or 1/0 "
]
},
{
"cell_type": "code",
"execution_count": 32,
"id": "1f56a7d2-4410-46fd-a276-c76b24f8a6bb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"False and 1/0"
]
},
{
"cell_type": "markdown",
"id": "91e3b4ea-5a3d-4688-bfb1-f9c3ae925a33",
"metadata": {},
"source": [
"https://duckduckgo.com/?t=ffab&q=boolean+short+circuit+python&ia=web"
]
},
{
"cell_type": "markdown",
"id": "79474399-7d9e-44cc-a747-f881e77c4784",
"metadata": {},
"source": [
"## resort uk /rɪˈzɔːt/ us /rɪˈzɔːrt/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "07d43a7a-dfb9-4f2f-9482-c4b31696d6c7",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "81886543-93a5-4fd0-9c51-a757845bac98",
"metadata": {},
"outputs": [],
"source": [
"True and False or not True "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fdf59b51-88b7-4b6c-a2b1-c15d2ad0eb89",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 33,
"id": "f5503303-301a-4783-abf0-a86d5d70d4b7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"True and (False or (not True ))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19e8212b-f0e5-43ab-a064-d7d84760d8c9",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "ec47759d-44f2-4355-b2e2-b293c604ab59",
"metadata": {},
"source": [
"## list (other langs: array, NOT linked list)"
]
},
{
"cell_type": "markdown",
"id": "3c3a9471-eb33-4de6-b91b-8a672238ec4a",
"metadata": {},
"source": [
"dùng để chứa nhiều thứ "
]
},
{
"cell_type": "code",
"execution_count": 34,
"id": "43d89a7b-dcb9-4cc4-82ca-15f999d1ca76",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1 "
]
},
{
"cell_type": "code",
"execution_count": 35,
"id": "b1a9bf7b-21fc-43cb-aee6-5a170942d9db",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"5"
]
},
{
"cell_type": "code",
"execution_count": 38,
"id": "497361ac-d631-457d-9a83-19c1500af770",
"metadata": {},
"outputs": [],
"source": [
"xs = [1,3,5]"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "d19eb792-c886-4c18-a58e-f7101832c7ec",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"list"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(xs)"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "c1b15760-6258-4b6f-9837-9d5751e1c2b6",
"metadata": {},
"outputs": [],
"source": [
"numbers = [1, 2.5, 3, 3.14, False, [1,3,9]]"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "afbe0149-c523-4349-a9c6-4ccb40b29d3e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"list"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(numbers)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "2f2d527e-681d-41c8-9e84-e7e4c12241d4",
"metadata": {},
"outputs": [],
"source": [
"ns = [2,1,3,4,5]"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "a3e02bbf-3efe-4e84-967e-870d73bc02f6",
"metadata": {},
"outputs": [],
"source": [
"ns = [123,12,31,23,12,31,23,123,12,31,2,13,12,3,123,12,31,23,12,31,23,12]"
]
},
{
"cell_type": "code",
"execution_count": 49,
"id": "d6e8337c-3b74-4d92-9d84-ef8930cbbcfc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"22"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(ns)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "2f80b3ca-e134-498d-9358-e34f292c71f5",
"metadata": {},
"outputs": [],
"source": [
"ns = [123,12,31,23,12,31,23,123,12,31,2,13,12,3,123,12,31,23,12,31,23,12,\n",
" 23,12,31,23,123,12,31,2,13,12,3,123,\n",
"23,12,31,23,123,12,31,\n",
" ]"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "b1a21d7b-e684-4620-b595-7df547631ff7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"41"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(ns)"
]
},
{
"cell_type": "markdown",
"id": "64d48613-2b1e-45bd-9f65-3e2359ef2c29",
"metadata": {},
"source": [
"## len - length "
]
},
{
"cell_type": "code",
"execution_count": 54,
"id": "00dc2f3e-3f7f-459c-87db-a14cf8f0a43d",
"metadata": {},
"outputs": [],
"source": [
"xs = []"
]
},
{
"cell_type": "code",
"execution_count": 55,
"id": "e0dedaa7-95b6-4fd7-ab92-93f561d73eca",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(xs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d5e991e4-0f94-4400-8fd4-b11cd8f819ae",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 56,
"id": "ec19fa31-931e-48d1-8321-e032a982f25d",
"metadata": {},
"outputs": [],
"source": [
"ns= [1,2,3,4,5]"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "405d3e73-b2bb-4800-a917-3bbc87fa311c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"15"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(ns)"
]
},
{
"cell_type": "markdown",
"id": "9e8fda53-183e-42c0-b0fa-4326be24eefb",
"metadata": {},
"source": [
"## Tính tổng các số từ 23 đến 85"
]
},
{
"cell_type": "code",
"execution_count": 60,
"id": "033d19c2-e953-43b6-b226-30d028dfc9d4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3402"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum([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,71,72,73,74,75,76,77,78,79,\n",
" 80,81,82,83,84,85])"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "c6fb20e2-7a25-4328-9db0-ab8814e422be",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5, 6, 7, 8, 9]"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list(range(1,10))"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "2f45c2fb-2a2f-464a-a375-012dcfab59a7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3402"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(list(range(23,86)))"
]
},
{
"cell_type": "markdown",
"id": "dbb58593-fc6f-4393-bb42-e4ca3991bbd8",
"metadata": {},
"source": [
"### tinh tong 1 1000"
]
},
{
"cell_type": "code",
"execution_count": 66,
"id": "28cb9425-85b8-44f7-a73e-680912c091c8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"500500"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(list(range(1,1001)))"
]
},
{
"cell_type": "markdown",
"id": "b8722729-893e-4a05-a2fa-c48fd6ce4594",
"metadata": {},
"source": [
"### BTVN: tinh tong 1 den 1 TY"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "c28b181c-61c9-4fb4-9570-5f11142e6301",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1000000000"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1_000_000_000"
]
},
{
"cell_type": "code",
"execution_count": 68,
"id": "dc47bc25-6cfa-4f58-b8bd-5d904d43b510",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"1000000000"
]
},
"execution_count": 68,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1000000000"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "47162060-28ef-429c-842e-5ca7e0171127",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "861508e9-ea01-4505-9317-f244522db02c",
"metadata": {},
"source": [
"## Indexing"
]
},
{
"cell_type": "code",
"execution_count": 70,
"id": "bf80d1f0-1707-43ed-be57-9970404c68b1",
"metadata": {},
"outputs": [],
"source": [
"xs = [400, 600, 800, 900]"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "64d221cd-7cd7-49e1-a969-8c000591a9e1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"400"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[0]"
]
},
{
"cell_type": "code",
"execution_count": 73,
"id": "24299125-e64a-4153-a131-7a53a4f762a5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"600"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[1]"
]
},
{
"cell_type": "code",
"execution_count": 74,
"id": "97821ffd-73c3-4591-9c06-01d461776010",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"800"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[2]"
]
},
{
"cell_type": "code",
"execution_count": 75,
"id": "b66d814e-0896-49ed-a7cd-915a906c7196",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"900"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"xs[3]"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "9dd7c5dd-4a1a-4424-b6f0-c9e76989c45e",
"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)",
"Cell \u001b[0;32mIn[76], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mxs\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m4\u001b[39;49m\u001b[43m]\u001b[49m\n",
"\u001b[0;31mIndexError\u001b[0m: list index out of range"
]
}
],
"source": [
"xs[4]"
]
},
{
"cell_type": "markdown",
"id": "058e3e4c-b5de-4c17-ab6e-c47100625cb0",
"metadata": {},
"source": [
"### 0 1 2 3 - index"
]
},
{
"cell_type": "markdown",
"id": "58bf81a0-9d80-45af-8308-acc4dbd0e03c",
"metadata": {},
"source": [
"### index - đếm từ 0"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de62bfb1-f937-479f-be9e-3a3228876fb8",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 77,
"id": "3a04c146-25cf-4114-95f0-a8a89cc594c5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5]"
]
},
"execution_count": 77,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fc68622f-623f-4de3-b515-4b65e30d61fb",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 78,
"id": "7897e6e2-78ba-4513-aac8-e8251a8085b5",
"metadata": {},
"outputs": [],
"source": [
"### lay phần tử cuối cùng"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "aa61b32c-3da2-45c1-82d3-91904ae0261f",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[len(ns)-1]"
]
},
{
"cell_type": "code",
"execution_count": 81,
"id": "20fd5fbe-4229-4136-865e-c95b07c0d76a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 81,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-1] ### ns[len(ns)-1]"
]
},
{
"cell_type": "code",
"execution_count": 80,
"id": "4b691115-4ea8-461b-9b2e-c2ea0ca77cb4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[len(ns)-2]"
]
},
{
"cell_type": "code",
"execution_count": 82,
"id": "e49892f7-9dd4-4a5b-b86a-a8c2e7f89646",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 82,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-2]"
]
},
{
"cell_type": "markdown",
"id": "c97d330c-681c-43a2-b282-7cfd888b84fc",
"metadata": {},
"source": [
"## negative index"
]
},
{
"cell_type": "code",
"execution_count": 84,
"id": "7cf3b482-1497-4348-be2f-1250171013cb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5]"
]
},
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns"
]
},
{
"cell_type": "markdown",
"id": "59597564-de13-4660-a578-07b3fdb536d9",
"metadata": {},
"source": [
"## 1 list chua 3 phan tu dau tien cua ns"
]
},
{
"cell_type": "markdown",
"id": "fd4b010f-cd23-4cd6-8860-84c72c721abe",
"metadata": {},
"source": [
"## slicing"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "1799f572-c947-4680-8cb1-a0c3735ecc3f",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3]"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"[ns[0], ns[1], ns[2]]"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "b35e39a3-4293-41a2-a14e-5e03c5890bfc",
"metadata": {},
"outputs": [],
"source": [
"bigns = list(range(3,1000))"
]
},
{
"cell_type": "markdown",
"id": "7f68aa49-9465-4469-b7e5-565d6db97647",
"metadata": {},
"source": [
"## 50 phan tu dau tien?"
]
},
{
"cell_type": "code",
"execution_count": 88,
"id": "54a2e78d-e44c-4bc5-b8d1-b06025c77bbe",
"metadata": {},
"outputs": [],
"source": [
"### lấy tập con của 1 list "
]
},
{
"cell_type": "code",
"execution_count": 92,
"id": "d397515a-b46b-4eb5-9443-73fbfdf4beda",
"metadata": {},
"outputs": [],
"source": [
"### list[start:stop]"
]
},
{
"cell_type": "code",
"execution_count": 93,
"id": "5957f594-9b80-4015-9816-d4fc66c82b22",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"50"
]
},
"execution_count": 93,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(bigns[0:50])"
]
},
{
"cell_type": "code",
"execution_count": 96,
"id": "485b8450-44b5-43d0-92a7-a362257a5a05",
"metadata": {
"scrolled": true
},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3]"
]
},
"execution_count": 96,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[0:3] # ns[0], ns[1], ns[2]"
]
},
{
"cell_type": "code",
"execution_count": 103,
"id": "f96a1d5d-4053-474c-9fce-e64254ce3aa7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3]"
]
},
"execution_count": 103,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[:3]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "240259eb-f9a3-4c57-b546-8e83a3401f69",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 104,
"id": "8b1ac57d-3689-43bb-aa04-35363367e27e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3]"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[:3]"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "1698dda4-69ef-4e71-b581-5b49db389e01",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[3, 4, 5]"
]
},
"execution_count": 105,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-3:]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0fd60eb3-2826-4488-942a-923ef9e1b78e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "ded156f0-22b4-43d0-88ea-c810a1d6a4d1",
"metadata": {},
"source": [
"### 2 phan tu cuoi "
]
},
{
"cell_type": "code",
"execution_count": 98,
"id": "65c4c134-96e4-46a8-94ee-35d82430eca0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5]"
]
},
"execution_count": 98,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "d8fe0c46-578a-4c27-8152-0b23a80f04c0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[4, 5]"
]
},
"execution_count": 100,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-2:len(ns)]"
]
},
{
"cell_type": "code",
"execution_count": 102,
"id": "80a50495-e832-4121-82a9-1d932ba99206",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[4, 5]"
]
},
"execution_count": 102,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[-2:] # tu index -2 dne cuoi"
]
},
{
"cell_type": "code",
"execution_count": 107,
"id": "d83ae889-5ac7-47e9-9b42-c992033e3c02",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5]"
]
},
"execution_count": 107,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns"
]
},
{
"cell_type": "code",
"execution_count": 109,
"id": "a7b1d612-ae6c-4c5d-bf94-0bdd9d6432bc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3, 4, 5]"
]
},
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns[:] # shallow copy of ns"
]
},
{
"cell_type": "code",
"execution_count": 114,
"id": "30d5a8a8-487d-41db-9837-d760fc8f5e0c",
"metadata": {},
"outputs": [],
"source": [
"ns[2] = 999 # item assignment"
]
},
{
"cell_type": "code",
"execution_count": 115,
"id": "81ea1089-9e1b-46fa-8af4-a3f440da5352",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 999, 4, 5]"
]
},
"execution_count": 115,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ns"
]
},
{
"cell_type": "code",
"execution_count": 116,
"id": "17ce5c56-384d-47e9-8541-b2a6d542597d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tue Mar 12 08:45:26 PM +07 2024\n"
]
}
],
"source": [
"!date"
]
},
{
"cell_type": "markdown",
"id": "b17c8d58-7c97-48ea-b6a2-e5db84a58955",
"metadata": {},
"source": [
"## chuan bi buoi 3"
]
},
{
"cell_type": "markdown",
"id": "0abb3bba-092d-46e6-ad7a-d72d6b7e4a40",
"metadata": {},
"source": [
"https://gitlab.com/pyfml/prepare#chu%E1%BA%A9n-b%E1%BB%8B-tr%C6%B0%E1%BB%9Bc-bu%E1%BB%95i-3"
]
},
{
"cell_type": "markdown",
"id": "986ac0e9-75fb-4660-8d99-cfbd3243a486",
"metadata": {},
"source": [
"send slackname/git name to me@h432ng.xyz"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "57cc383c-3e7e-4e0f-b089-4b80f7836d84",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "5b716dd4-1d08-4fbe-b135-cdc423e9fbfd",
"metadata": {},
"source": [
"\n",
"## string : text \n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 117,
"id": "fadb2fa8-404f-48bb-bb9a-d2a59707e6f3",
"metadata": {},
"outputs": [],
"source": [
"s = \"chị ong nâu nâu nâu nâu\""
]
},
{
"cell_type": "code",
"execution_count": 118,
"id": "effec233-1d70-4144-8082-e46bb378b5cf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"str"
]
},
"execution_count": 118,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"type(s)"
]
},
{
"cell_type": "code",
"execution_count": 119,
"id": "04aa1f01-ce09-4102-8b1d-ddcb2c890550",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"23"
]
},
"execution_count": 119,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(s)"
]
},
{
"cell_type": "code",
"execution_count": 122,
"id": "3ad044f7-4959-4bf8-b729-1ba00da9b017",
"metadata": {},
"outputs": [],
"source": [
"s = \"😍\" # emoji"
]
},
{
"cell_type": "code",
"execution_count": 121,
"id": "c65200bd-c688-492c-8f4c-14399b4024f6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 121,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(s)"
]
},
{
"cell_type": "markdown",
"id": "47fc55f1-13cb-4816-8f85-cd299973cf31",
"metadata": {},
"source": [
"### định nghĩa "
]
},
{
"cell_type": "code",
"execution_count": 123,
"id": "827343ad-8bab-429a-80f0-26cc88bb9f48",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'noi dung'"
]
},
"execution_count": 123,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\"noi dung\""
]
},
{
"cell_type": "markdown",
"id": "a23f83cd-0b1a-4f03-a437-be832b767a63",
"metadata": {},
"source": [
"### \" - tên là gì?: double quote"
]
},
{
"cell_type": "markdown",
"id": "19b12815-6013-48f7-8192-62a87e1b78e9",
"metadata": {
"scrolled": true
},
"source": [
"- ngoặc kép"
]
},
{
"cell_type": "code",
"execution_count": 125,
"id": "a3496d9d-7f30-4419-bcfb-240facf2dd71",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"str"
]
},
"execution_count": 125,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s = 'noi dung'\n",
"type(s)"
]
},
{
"cell_type": "markdown",
"id": "dab28022-00d1-4e2f-8b4a-939072ace8e3",
"metadata": {},
"source": [
"' - tên là gì: single quote \n",
"\n",
"- ngoặc đơn"
]
},
{
"cell_type": "markdown",
"id": "2b612486-a746-473f-b313-c5887409f099",
"metadata": {},
"source": [
") dấu gì? "
]
},
{
"cell_type": "markdown",
"id": "9efc5b59-9002-45d1-8358-4d25b39b8306",
"metadata": {},
"source": [
"### \"\"\" - triple quote"
]
},
{
"cell_type": "code",
"execution_count": 127,
"id": "75fc5773-9433-4b23-8567-2baf86106224",
"metadata": {},
"outputs": [],
"source": [
"s1 = 'hihi'\n",
"s2 = \"hihi\""
]
},
{
"cell_type": "code",
"execution_count": 128,
"id": "f72d07bf-2175-42c9-b299-02b36abbe57c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 128,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s1 == s2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f57165ad-9193-4fbc-8430-ae86e23bf282",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "780a6c99-428f-4990-bd3c-8d33571d8f0e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "e76202f2-1c91-4d63-a051-98a118212d5b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 129,
"id": "47d29763-de0f-4e54-9d69-9850d0947df4",
"metadata": {},
"outputs": [],
"source": [
"s = \"hihfiashdflijadf\""
]
},
{
"cell_type": "code",
"execution_count": 130,
"id": "99351778-06b2-4d30-a2df-4bbbce690260",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "unterminated string literal (detected at line 1) (2601796113.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[130], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m s = \"day la double quote \" ne\"\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unterminated string literal (detected at line 1)\n"
]
}
],
"source": [
"s = \"day la double quote \" ne\" "
]
},
{
"cell_type": "code",
"execution_count": 131,
"id": "ebc1ccf1-e7d1-4676-a501-d3c89813967d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"day la double quote \" ne\n"
]
}
],
"source": [
"s = 'day la double quote \" ne'\n",
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 134,
"id": "fb753058-3d58-4d0b-8391-3965260a706a",
"metadata": {},
"outputs": [],
"source": [
"s = \"Hello I'm Peter\""
]
},
{
"cell_type": "code",
"execution_count": 135,
"id": "fab7ee28-a419-4859-adb2-84e23aaea3ac",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello I'm Peter\n"
]
}
],
"source": [
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3d19642-e5aa-4f6d-b9d7-c19730914f9f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "bbdea1fb-e5f5-4901-a695-1511bb044ab2",
"metadata": {},
"source": [
"### escape string - using backslash"
]
},
{
"cell_type": "code",
"execution_count": 137,
"id": "0f2dbe3b-8bc7-424d-8df7-3e14aeed8996",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"day la double quote \" ne\n"
]
}
],
"source": [
"s = \"day la double quote \\\" ne\" \n",
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 138,
"id": "1d120569-f5d4-4b21-80a5-11f0f5402364",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello I'm Peter\n"
]
}
],
"source": [
"s = 'Hello I\\'m Peter'\n",
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 140,
"id": "44ebd653-e1a6-4ea5-b05d-8f1393829da7",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "unterminated string literal (detected at line 1) (2854750865.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[140], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m s = \"Chị ong nâu nâu nâu nâu\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unterminated string literal (detected at line 1)\n"
]
}
],
"source": [
"s = \"Chị ong nâu nâu nâu nâu\n",
"Chị bay đi đâu đi đâu\""
]
},
{
"cell_type": "markdown",
"id": "63b01771-c28f-4e2a-abb8-f778ec893160",
"metadata": {},
"source": [
"### enter sinh ra ký tự newline \\n"
]
},
{
"cell_type": "code",
"execution_count": 142,
"id": "720dd79b-6f40-4b24-883f-8afdeb450fe0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a\n",
"b\n"
]
}
],
"source": [
"s = \"a\\nb\"\n",
"print(s)"
]
},
{
"cell_type": "markdown",
"id": "322334f3-ee17-45d1-b477-22b9f9584e8c",
"metadata": {},
"source": [
"Windows: carriage return line feed (CR LF)"
]
},
{
"cell_type": "code",
"execution_count": 144,
"id": "1890e204-53b9-4333-86b4-61f8b22bfdb4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a\tb\n",
"c d\n"
]
}
],
"source": [
"print(\"a\\tb\\nc d\")"
]
},
{
"cell_type": "code",
"execution_count": 145,
"id": "548c5ac8-d8df-42f6-9145-fbb1c902e723",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Chị ong nâu nâu nâu nâu\n",
"Chị bay đi đâu đi đâu\n"
]
}
],
"source": [
"s = \"Chị ong nâu nâu nâu nâu\\nChị bay đi đâu đi đâu\"\n",
"print(s)"
]
},
{
"cell_type": "markdown",
"id": "e7d68a18-ab57-49ba-b9be-af0d8d04fd30",
"metadata": {},
"source": [
"\"\"\"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 148,
"id": "8a5cdd87-863e-44ae-b273-795972c7ea5e",
"metadata": {},
"outputs": [],
"source": [
"s = \"\"\"Chị ong nâu nâu nâu nâu\n",
"Chị bay đi đâu đi đâu\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 149,
"id": "040a1bd7-3f03-4153-8434-caf0f59b1883",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Chị ong nâu nâu nâu nâu\n",
"Chị bay đi đâu đi đâu\n"
]
}
],
"source": [
"print(s)"
]
},
{
"cell_type": "code",
"execution_count": 150,
"id": "98efcaa1-f736-4901-9249-5209298c9c6c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Chị ong nâu nâu nâu nâu\\nChị bay đi đâu đi đâu'"
]
},
"execution_count": 150,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s"
]
},
{
"cell_type": "code",
"execution_count": 152,
"id": "2a9c043a-188b-4b03-980d-c278b458db39",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'C'"
]
},
"execution_count": 152,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s[0]"
]
},
{
"cell_type": "code",
"execution_count": 153,
"id": "09570534-c887-4e83-b7f3-c41871a00334",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'u'"
]
},
"execution_count": 153,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s[-1]"
]
},
{
"cell_type": "code",
"execution_count": 154,
"id": "ad4d8e33-c4b9-4c88-bcd2-c5640b8cd2a6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'đâu đi đâu'"
]
},
"execution_count": 154,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"s[-10:]"
]
},
{
"cell_type": "markdown",
"id": "475843fb-1abc-4b1b-ab11-75fcff7500a8",
"metadata": {},
"source": [
"### BTVN: đọc tài liệu 3.1.2\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37530a70-20ea-41fe-a506-2e1f9cc24310",
"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.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment