From 48fcc32f7313eeda66daccc63c9a7dee8e421f0b Mon Sep 17 00:00:00 2001 From: bushuhui Date: Sun, 12 Jul 2020 21:56:23 +0800 Subject: [PATCH] Improve python tutorials --- 0_python/1_Basics.ipynb | 59 +++++++++++----- 0_python/2_Print_Statement.ipynb | 26 ++++--- 0_python/3_Data_Structure_1.ipynb | 22 +++--- 0_python/4_Data_Structure_2.ipynb | 10 +-- 0_python/5_Control_Flow.ipynb | 20 +++--- 0_python/6_Function.ipynb | 140 ++++++++++---------------------------- 0_python/7_Class.ipynb | 18 +++-- 0_python/README.md | 1 + README.md | 1 - 9 files changed, 128 insertions(+), 169 deletions(-) diff --git a/0_python/1_Basics.ipynb b/0_python/1_Basics.ipynb index ae2c7e9..f1528ae 100644 --- a/0_python/1_Basics.ipynb +++ b/0_python/1_Basics.ipynb @@ -20,15 +20,38 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## import\n", - "\n", - "```\n", + "## 1. import & Zen of Python\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['1_Basics.ipynb',\n", + " '2_Print_Statement.ipynb',\n", + " '3_Data_Structure_1.ipynb',\n", + " '4_Data_Structure_2.ipynb',\n", + " '5_Control_Flow.ipynb',\n", + " '6_Function.ipynb',\n", + " '7_Class.ipynb',\n", + " 'Python.pdf',\n", + " 'README.md',\n", + " '.ipynb_checkpoints']" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 导入库\n", "import os\n", - "```\n", - "\n", - "$$\n", - "f(x) = sin(x)\n", - "$$" + "os.listdir('.')" ] }, { @@ -72,7 +95,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Variables" + "## 2. Variables" ] }, { @@ -147,14 +170,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Operators" + "## 3. Operators" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Arithmetic Operators" + "### 3.1 Arithmetic Operators" ] }, { @@ -350,7 +373,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Relational Operators" + "### 3.2 Relational Operators" ] }, { @@ -420,7 +443,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Bitwise Operators" + "### 3.3 Bitwise Operators" ] }, { @@ -532,7 +555,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Built-in Functions" + "## 4. Built-in Functions" ] }, { @@ -546,7 +569,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Conversion from one system to another" + "### 4.1 Conversion from one system to another" ] }, { @@ -721,7 +744,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Simplifying Arithmetic Operations" + "### 4.2 Simplifying Arithmetic Operations" ] }, { @@ -920,7 +943,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Accepting User Inputs" + "### 4.3 Accepting User Inputs" ] }, { @@ -984,7 +1007,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/0_python/2_Print_Statement.ipynb b/0_python/2_Print_Statement.ipynb index e7322e8..650f004 100644 --- a/0_python/2_Print_Statement.ipynb +++ b/0_python/2_Print_Statement.ipynb @@ -231,7 +231,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Other Examples" + "## 1. Other Examples" ] }, { @@ -342,31 +342,35 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 2, "metadata": {}, "outputs": [ { - "ename": "SyntaxError", - "evalue": "Missing parentheses in call to 'print' (, line 5)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m5\u001b[0m\n\u001b[0;31m \"\"\"\u001b[0m\n\u001b[0m \n^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m Missing parentheses in call to 'print'\n" + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Routine:\n", + "\t- Eat\n", + "\t- Sleep\n", + "\t- Repeat\n", + "\n" ] } ], "source": [ - "print \"\"\"\n", + "print(\"\"\"\n", "Routine:\n", "\\t- Eat\n", "\\t- Sleep\\n\\t- Repeat\n", - "\"\"\"" + "\"\"\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# PrecisionWidth and FieldWidth" + "# 2. PrecisionWidth and FieldWidth" ] }, { @@ -575,7 +579,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/0_python/3_Data_Structure_1.ipynb b/0_python/3_Data_Structure_1.ipynb index 1110741..0d4bd2c 100644 --- a/0_python/3_Data_Structure_1.ipynb +++ b/0_python/3_Data_Structure_1.ipynb @@ -18,7 +18,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Lists" + "## 1. Lists" ] }, { @@ -85,7 +85,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Indexing" + "### 1.1 Indexing" ] }, { @@ -296,7 +296,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Slicing" + "### 1.2 Slicing" ] }, { @@ -380,7 +380,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Built in List Functions" + "### 1.3 Built in List Functions" ] }, { @@ -1202,7 +1202,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Copying a list" + "### 1.4 Copying a list" ] }, { @@ -1362,7 +1362,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Tuples" + "## 2. Tuples" ] }, { @@ -1531,7 +1531,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Mapping one tuple to another" + "### 2.1 Mapping one tuple to another" ] }, { @@ -1582,7 +1582,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Built In Tuple functions" + "### 2.2 Built In Tuple functions" ] }, { @@ -1643,7 +1643,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Sets" + "## 3. Sets" ] }, { @@ -1702,7 +1702,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Built-in Functions" + "### 3.1 Built-in Functions" ] }, { @@ -1991,7 +1991,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/0_python/4_Data_Structure_2.ipynb b/0_python/4_Data_Structure_2.ipynb index 2712347..20e71bb 100644 --- a/0_python/4_Data_Structure_2.ipynb +++ b/0_python/4_Data_Structure_2.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Strings" + "## 1. Strings" ] }, { @@ -88,7 +88,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Built-in Functions" + "### 1.1 Built-in Functions" ] }, { @@ -792,7 +792,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Dictionaries" + "## 2. Dictionaries" ] }, { @@ -971,7 +971,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Built-in Functions" + "### 2.1 Built-in Functions" ] }, { @@ -1172,7 +1172,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/0_python/5_Control_Flow.ipynb b/0_python/5_Control_Flow.ipynb index bdb7aef..493ab56 100644 --- a/0_python/5_Control_Flow.ipynb +++ b/0_python/5_Control_Flow.ipynb @@ -11,7 +11,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## If" + "## 1. If" ] }, { @@ -48,7 +48,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## If-else" + "## 2. If-else" ] }, { @@ -89,7 +89,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## if-elif" + "## 3. if-elif" ] }, { @@ -173,14 +173,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Loops" + "## 4. Loops" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### For" + "### 4.1 For" ] }, { @@ -307,7 +307,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### While" + "### 4.2 While" ] }, { @@ -363,7 +363,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Break" + "## 5. Break" ] }, { @@ -404,7 +404,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Continue" + "## 6. Continue" ] }, { @@ -449,7 +449,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## List Comprehensions" + "## 7. List Comprehensions" ] }, { @@ -685,7 +685,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/0_python/6_Function.ipynb b/0_python/6_Function.ipynb index 56423aa..14e1e6a 100644 --- a/0_python/6_Function.ipynb +++ b/0_python/6_Function.ipynb @@ -209,7 +209,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Return Statement" + "## 1. Return Statement" ] }, { @@ -415,7 +415,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Implicit arguments" + "## 2. Implicit arguments" ] }, { @@ -520,7 +520,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Any number of arguments" + "## 3. Any number of arguments" ] }, { @@ -645,7 +645,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Global and Local Variables" + "## 4. Global and Local Variables" ] }, { @@ -657,7 +657,7 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -673,127 +673,61 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def egfunc1():\n", - " def thirdfunc(arg1):\n", - " eg2 = arg1[:]\n", - " #eg2 = arg1\n", - " eg2.append(6)\n", - " print(\"This is happening inside the function :\", eg2)\n", - " \n", - " # what's the difference between following two lines?\n", - " #eg1.append(7)\n", " eg1 = [1, 2, 3, 4, 5, 7]\n", - " \n", - " print(\"This is happening before the function is called : \", eg1)\n", - " thirdfunc(eg1)\n", - " \n", - " print(\"This is happening outside the function :\", eg1) \n", - " #print(\"Accessing a variable declared inside the function from outside :\" , eg2)" - ] - }, - { - "cell_type": "code", - "execution_count": 43, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "This is happening before the function is called : [1, 2, 3, 4, 5, 7]\n", - "This is happening inside the function : [1, 2, 3, 4, 5, 7, 6]\n", - "This is happening outside the function : [1, 2, 3, 4, 5, 7]\n", - "[1, 2, 3, 4, 5]\n" - ] - } - ], - "source": [ - "egfunc1()\n", - "print(eg1)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "If a **global** variable is defined as shown in the example below then that variable can be called from anywhere." - ] - }, - { - "cell_type": "code", - "execution_count": 27, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n" - ] - } - ], - "source": [ - "eg3 = [1,2,3,4,5]" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - ":8: SyntaxWarning: name 'eg1' is used prior to global declaration\n", - " global eg1\n" - ] - } - ], - "source": [ - "def egfunc1():\n", - " def thirdfunc(arg1):\n", - " global eg2\n", - " eg2 = arg1[:]\n", - " eg2.append(6)\n", - " print(\"This is happening inside the function :\", eg2)\n", - " print(\"This is happening before the function is called : \", eg1)\n", + " print(\"egfunc1>> eg1: \", eg1)\n", + "\n", + "def egfunc2():\n", + " eg1.append(8)\n", + " print(\"egfunc2>> eg1: \", eg1)\n", + "\n", + "def egfunc3():\n", " global eg1\n", - " eg1 = [1, 2, 3, 4, 5, 7]\n", - " thirdfunc(eg1)\n", - " print(\"This is happening outside the function :\", eg1) \n", - " print(\"Accessing a variable declared inside the function from outside :\" , eg2)" + " eg1 = [5, 4, 3, 2, 1]\n", + " print(\"egfunc3>> eg1: \", eg1)" ] }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "This is happening before the function is called : [1, 2, 3, 4, 5]\n", - "This is happening inside the function : [1, 2, 3, 4, 5, 6]\n", - "This is happening outside the function : [1, 2, 3, 4, 5]\n", - "Accessing a variable declared inside the function from outside : [1, 2, 3, 4, 5, 6]\n" + "egfunc1>> eg1: [1, 2, 3, 4, 5, 7]\n", + "eg1: [1, 2, 3, 4, 5] \n", + "\n", + "egfunc2>> eg1: [1, 2, 3, 4, 5, 8]\n", + "eg1: [1, 2, 3, 4, 5, 8] \n", + "\n", + "egfunc3>> eg1: [5, 4, 3, 2, 1]\n", + "eg1: [5, 4, 3, 2, 1] \n", + "\n" ] } ], "source": [ - "egfunc1()" + "egfunc1()\n", + "print(\"eg1: \", eg1, \"\\n\")\n", + "\n", + "egfunc2()\n", + "print(\"eg1: \", eg1, \"\\n\")\n", + "\n", + "egfunc3()\n", + "print(\"eg1: \", eg1, \"\\n\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Lambda Functions" + "## 5. Lambda Functions" ] }, { @@ -900,7 +834,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### map" + "### 5.1 map" ] }, { @@ -1018,7 +952,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### filter" + "### 5.2 filter" ] }, { @@ -1133,7 +1067,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/0_python/7_Class.ipynb b/0_python/7_Class.ipynb index 1db0b34..4665ff7 100644 --- a/0_python/7_Class.ipynb +++ b/0_python/7_Class.ipynb @@ -765,7 +765,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Inheritance" + "## 1. Inheritance" ] }, { @@ -1270,19 +1270,17 @@ "Now that you have been introduced to python, You can try out the different python libraries in the field of your interest. I highly recommend you to check out this curated list of Python frameworks, libraries and software http://awesome-python.com\n", "\n", "\n", - "The official python documentation : https://docs.python.org/2/\n", + "The official python documentation : https://docs.python.org/3/\n", "\n", + "Pyton tutorials:\n", + "* [Python tutorial (廖雪峰)](https://www.liaoxuefeng.com/wiki/1016959663602400)\n", + "* [Python基础教程](https://www.runoob.com/python/python-tutorial.html)\n", + "* [Python官方教程(中文版)](https://docs.python.org/zh-cn/3/tutorial/index.html)\n", "\n", "You can also check out Python practice programs written by my friend, Kartik Kannapur. Github Repo : https://github.com/rajathkumarmp/Python-Lectures \n", "\n", "\n", - "Enjoy solving problem statements because life is short, you need python!\n", - "\n", - "\n", - "Peace.\n", - "\n", - "\n", - "Rajath Kumar M.P ( rajathkumar dot exe at gmail dot com)" + "Enjoy solving problem statements because life is short, you need python!\n" ] } ], @@ -1302,7 +1300,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.2" + "version": "3.6.8" } }, "nbformat": 4, diff --git a/0_python/README.md b/0_python/README.md index 2c09acb..a91dcad 100644 --- a/0_python/README.md +++ b/0_python/README.md @@ -6,6 +6,7 @@ Python 是一门上手简单、功能强大、通用型的脚本编程语言。P 本教程来自[IPython Notebooks to learn Python](https://github.com/rajathkmp/Python-Lectures),将其中部分示例代码转化成Python3。关于Python的按照可以自行去网络上查找相关的资料,或者参考[安装Python环境](../tips/InstallPython.md)。 ## 内容 +0. [Install Python](../tips/InstallPython.md) 1. [Basics](1_Basics.ipynb) - Why Python, Zen of Python - Variables, Operators, Built-in functions diff --git a/README.md b/README.md index b81fee0..5694f8e 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ 1. [课程简介](CourseIntroduction.pdf) 2. [Python](0_python/) - [Install Python](tips/InstallPython.md) - - [Introduction](0_python/0_Introduction.ipynb) - [Python Basics](0_python/1_Basics.ipynb) - [Print Statement](0_python/2_Print_Statement.ipynb) - [Data Structure 1](0_python/3_Data_Structure_1.ipynb)