Last active
June 26, 2019 13:03
-
-
Save phwt/4749e6cc67f26122db020742e3324d5c to your computer and use it in GitHub Desktop.
Python-T1
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": [ | |
{ | |
"metadata": { | |
"collapsed": true | |
}, | |
"cell_type": "markdown", | |
"source": "# Order of Operations - ลำดับการดำเนินการ\n## PEMDAS\n1. **P**arentheses - วงเล็บ | (x)\n2. **E**xponent - เลขยกกำลัง | x<sup>2</sup>\n3. **M**ultiplication and **D**ivision - การหาร และคูณ | 2 * 3, 12 / 8 _(ทำจากซ้ายไปขวา)_\n4. **A**ddition and **S**ubtraction - การบวกและ ลบ | 1 + 9, 22 - 6 *(ทำจากซ้ายไปขวา)*\n\n## Example\n\n### 3 + 3 * 3 - 3 + 3\n1. 3 + **3 * 3** - 3 + 3 (คูณและหาร)\n2. 3 + 9 - 3 + 3 (บวกและลบ)\n 1. **3 + 9** - 3 + 3 (หากมีหลายตัวทำจากซ้ายมาขวา)\n 2. **12 - 3** + 3\n 3. **9 + 3**\n\n**Result: 12**\n" | |
}, | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "3 + 3 * 3 - 3 + 3", | |
"execution_count": 3, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "12" | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "### 30 - 12 / (6 - 2) + 6 * 2<sup>3</sup>\n1. 30 - 12 / **(6 - 2)** + 6 x 2<sup>3</sup> (ในวงเล็บ)\n2. 30 - 12 / 4 + 6 * **2<sup>3</sup>** (ตัวยกกำลัง)\n3. 30 - 12 / 4 + 6 * 8 (คูณและหาร)\n 1. 30 - **12 / 4** + 6 * 8 (หากมีหลายตัวทำจากซ้ายมาขวา)\n 2. 30 - 3 + **6 * 8**\n 3. 30 - 3 + 48\n4. 30 - 3 + 48 (บวกและลบ)\n 1. **30 - 3** + 48 (หากมีหลายตัวทำจากซ้ายมาขวา)\n 2. **27 + 48**\n\n**Result: 75**" | |
}, | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "30 - 12 / (6 - 2) + 6 * 2 ** 3", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": "75.0" | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "# Help Function\n\nใช้ `help()` เพื่อเรียกใช้ Help ในโหมด Interactive หรือใช้ `help(object)` เพื่อเรียกใช้ Help ในโหมดระบุคำสั่ง\n\n\n## Interactive Help" | |
}, | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "help()", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "\nWelcome to Python 3.6's help utility!\n\nIf this is your first time using Python, you should definitely check out\nthe tutorial on the Internet at http://docs.python.org/3.6/tutorial/.\n\nEnter the name of any module, keyword, or topic to get help on writing\nPython programs and using Python modules. To quit this help utility and\nreturn to the interpreter, just type \"quit\".\n\nTo get a list of available modules, keywords, symbols, or topics, type\n\"modules\", \"keywords\", \"symbols\", or \"topics\". Each module also comes\nwith a one-line summary of what it does; to list the modules whose name\nor summary contain a given string such as \"spam\", type \"modules spam\".\n\nhelp> print\nHelp on built-in function print in module builtins:\n\nprint(...)\n print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n \n Prints the values to a stream, or to sys.stdout by default.\n Optional keyword arguments:\n file: a file-like object (stream); defaults to the current sys.stdout.\n sep: string inserted between values, default a space.\n end: string appended after the last value, default a newline.\n flush: whether to forcibly flush the stream.\n\n\nYou are now leaving help and returning to the Python interpreter.\nIf you want to ask for help on a particular object directly from the\ninterpreter, you can type \"help(object)\". Executing \"help('string')\"\nhas the same effect as typing a particular string at the help> prompt.\n" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "## Object specific help" | |
}, | |
{ | |
"metadata": { | |
"trusted": false | |
}, | |
"cell_type": "code", | |
"source": "help(print)", | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": "Help on built-in function print in module builtins:\n\nprint(...)\n print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n \n Prints the values to a stream, or to sys.stdout by default.\n Optional keyword arguments:\n file: a file-like object (stream); defaults to the current sys.stdout.\n sep: string inserted between values, default a space.\n end: string appended after the last value, default a newline.\n flush: whether to forcibly flush the stream.\n\n" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "## การอ่าน Help\n\n### ตัวอย่าง Output ของ help(print)\n\n print(...)\n print(value, ..., sep=' ', end='\\n', file=sys.stdout, flush=False)\n \n Prints the values to a stream, or to sys.stdout by default.\n Optional keyword arguments:\n file: a file-like object (stream); defaults to the current sys.stdout.\n sep: string inserted between values, default a space.\n end: string appended after the last value, default a newline.\n flush: whether to forcibly flush the stream.\n \n-----\n# Variable\n\nVarible หรือตัวแปรใน Python จะมีหลักๆอยู่ 3 ประเภทดังนี้\n* `int` - จำนวนเต็ม เช่น `44` `112` `1945`\n* `float` - จำนวนจริง เช่น `3.14` `291.02`\n* `string` - ตัวหนังสือ เช่น `Hello There!` `General Kenobi!`\n\nโดยสามารถใช้คำสั่ง `type()` ในการตรวจสอบประเภทตัวแปรได้" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "print(type(123))\nprint(type(356.23))\nprint(type(\"Senate\"))", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "<class 'int'>\n<class 'float'>\n<class 'str'>\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "ตัวแปรสามารถกำหนดชื่อให้มันได้ดังตัวอย่างนี้" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "num = 5\nlat = 1.024561\nname = \"Ben\"\nprint(num)\nprint(lat)\nprint(name)", | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "5\n1.024561\nBen\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "การเรียกใช้งานตัวแปรนั้นไม่สามารถเรียกใช้งานก่อนมีการประกาศตัวแปรได้ดังตัวอย่างนี้" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "a = 1\nprint(a)\nprint(b)\nb = 2", | |
"execution_count": 6, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "1\n", | |
"name": "stdout" | |
}, | |
{ | |
"output_type": "error", | |
"ename": "NameError", | |
"evalue": "name 'b' is not defined", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-6-2545e9da6b4e>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0ma\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mb\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;31mNameError\u001b[0m: name 'b' is not defined" | |
] | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "ดังตัวอย่างเมื่อมีการเรียกค่า `b` จะได้รับแจ้งว่า `NameError` เพราะยังไม่ได้ประกาศและกำหนดค่าให้ตัวแปร `b` ทำให้ไม่สามารถเรียกใช้ได้" | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "", | |
"execution_count": null, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python36", | |
"display_name": "Python 3.6", | |
"language": "python" | |
}, | |
"language_info": { | |
"mimetype": "text/x-python", | |
"nbconvert_exporter": "python", | |
"name": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.6", | |
"file_extension": ".py", | |
"codemirror_mode": { | |
"version": 3, | |
"name": "ipython" | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment