Browse Source

Improve python tutorials

pull/1/MERGE
bushuhui 5 years ago
parent
commit
48fcc32f73
9 changed files with 128 additions and 169 deletions
  1. +41
    -18
      0_python/1_Basics.ipynb
  2. +15
    -11
      0_python/2_Print_Statement.ipynb
  3. +11
    -11
      0_python/3_Data_Structure_1.ipynb
  4. +5
    -5
      0_python/4_Data_Structure_2.ipynb
  5. +10
    -10
      0_python/5_Control_Flow.ipynb
  6. +37
    -103
      0_python/6_Function.ipynb
  7. +8
    -10
      0_python/7_Class.ipynb
  8. +1
    -0
      0_python/README.md
  9. +0
    -1
      README.md

+ 41
- 18
0_python/1_Basics.ipynb View File

@@ -20,15 +20,38 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "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", "import os\n",
"```\n",
"\n",
"$$\n",
"f(x) = sin(x)\n",
"$$"
"os.listdir('.')"
] ]
}, },
{ {
@@ -72,7 +95,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Variables"
"## 2. Variables"
] ]
}, },
{ {
@@ -147,14 +170,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Operators"
"## 3. Operators"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Arithmetic Operators"
"### 3.1 Arithmetic Operators"
] ]
}, },
{ {
@@ -350,7 +373,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Relational Operators"
"### 3.2 Relational Operators"
] ]
}, },
{ {
@@ -420,7 +443,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Bitwise Operators"
"### 3.3 Bitwise Operators"
] ]
}, },
{ {
@@ -532,7 +555,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Built-in Functions"
"## 4. Built-in Functions"
] ]
}, },
{ {
@@ -546,7 +569,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Conversion from one system to another"
"### 4.1 Conversion from one system to another"
] ]
}, },
{ {
@@ -721,7 +744,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Simplifying Arithmetic Operations"
"### 4.2 Simplifying Arithmetic Operations"
] ]
}, },
{ {
@@ -920,7 +943,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Accepting User Inputs"
"### 4.3 Accepting User Inputs"
] ]
}, },
{ {
@@ -984,7 +1007,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 15
- 11
0_python/2_Print_Statement.ipynb View File

@@ -231,7 +231,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Other Examples"
"## 1. Other Examples"
] ]
}, },
{ {
@@ -342,31 +342,35 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18,
"execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "SyntaxError",
"evalue": "Missing parentheses in call to 'print' (<ipython-input-18-92e95899b5a9>, line 5)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-18-92e95899b5a9>\"\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": [ "source": [
"print \"\"\"\n",
"print(\"\"\"\n",
"Routine:\n", "Routine:\n",
"\\t- Eat\n", "\\t- Eat\n",
"\\t- Sleep\\n\\t- Repeat\n", "\\t- Sleep\\n\\t- Repeat\n",
"\"\"\""
"\"\"\")"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# PrecisionWidth and FieldWidth"
"# 2. PrecisionWidth and FieldWidth"
] ]
}, },
{ {
@@ -575,7 +579,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 11
- 11
0_python/3_Data_Structure_1.ipynb View File

@@ -18,7 +18,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Lists"
"## 1. Lists"
] ]
}, },
{ {
@@ -85,7 +85,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Indexing"
"### 1.1 Indexing"
] ]
}, },
{ {
@@ -296,7 +296,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Slicing"
"### 1.2 Slicing"
] ]
}, },
{ {
@@ -380,7 +380,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Built in List Functions"
"### 1.3 Built in List Functions"
] ]
}, },
{ {
@@ -1202,7 +1202,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Copying a list"
"### 1.4 Copying a list"
] ]
}, },
{ {
@@ -1362,7 +1362,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Tuples"
"## 2. Tuples"
] ]
}, },
{ {
@@ -1531,7 +1531,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Mapping one tuple to another"
"### 2.1 Mapping one tuple to another"
] ]
}, },
{ {
@@ -1582,7 +1582,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Built In Tuple functions"
"### 2.2 Built In Tuple functions"
] ]
}, },
{ {
@@ -1643,7 +1643,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Sets"
"## 3. Sets"
] ]
}, },
{ {
@@ -1702,7 +1702,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Built-in Functions"
"### 3.1 Built-in Functions"
] ]
}, },
{ {
@@ -1991,7 +1991,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 5
- 5
0_python/4_Data_Structure_2.ipynb View File

@@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Strings"
"## 1. Strings"
] ]
}, },
{ {
@@ -88,7 +88,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Built-in Functions"
"### 1.1 Built-in Functions"
] ]
}, },
{ {
@@ -792,7 +792,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Dictionaries"
"## 2. Dictionaries"
] ]
}, },
{ {
@@ -971,7 +971,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Built-in Functions"
"### 2.1 Built-in Functions"
] ]
}, },
{ {
@@ -1172,7 +1172,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 10
- 10
0_python/5_Control_Flow.ipynb View File

@@ -11,7 +11,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## If"
"## 1. If"
] ]
}, },
{ {
@@ -48,7 +48,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## If-else"
"## 2. If-else"
] ]
}, },
{ {
@@ -89,7 +89,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## if-elif"
"## 3. if-elif"
] ]
}, },
{ {
@@ -173,14 +173,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Loops"
"## 4. Loops"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### For"
"### 4.1 For"
] ]
}, },
{ {
@@ -307,7 +307,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### While"
"### 4.2 While"
] ]
}, },
{ {
@@ -363,7 +363,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Break"
"## 5. Break"
] ]
}, },
{ {
@@ -404,7 +404,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Continue"
"## 6. Continue"
] ]
}, },
{ {
@@ -449,7 +449,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## List Comprehensions"
"## 7. List Comprehensions"
] ]
}, },
{ {
@@ -685,7 +685,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 37
- 103
0_python/6_Function.ipynb View File

@@ -209,7 +209,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Return Statement"
"## 1. Return Statement"
] ]
}, },
{ {
@@ -415,7 +415,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Implicit arguments"
"## 2. Implicit arguments"
] ]
}, },
{ {
@@ -520,7 +520,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Any number of arguments"
"## 3. Any number of arguments"
] ]
}, },
{ {
@@ -645,7 +645,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Global and Local Variables"
"## 4. Global and Local Variables"
] ]
}, },
{ {
@@ -657,7 +657,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 41,
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -673,127 +673,61 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42,
"execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"def egfunc1():\n", "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", " 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": [
"<ipython-input-44-9b54e42c4e6f>: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", " 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", "cell_type": "code",
"execution_count": 29,
"execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "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": [ "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", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Lambda Functions"
"## 5. Lambda Functions"
] ]
}, },
{ {
@@ -900,7 +834,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### map"
"### 5.1 map"
] ]
}, },
{ {
@@ -1018,7 +952,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### filter"
"### 5.2 filter"
] ]
}, },
{ {
@@ -1133,7 +1067,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 8
- 10
0_python/7_Class.ipynb View File

@@ -765,7 +765,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "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", "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",
"\n", "\n",
"The official python documentation : https://docs.python.org/2/\n",
"The official python documentation : https://docs.python.org/3/\n",
"\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", "\n",
"You can also check out Python practice programs written by my friend, Kartik Kannapur. Github Repo : https://github.com/rajathkumarmp/Python-Lectures \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",
"\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", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.5.2"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 1
- 0
0_python/README.md View File

@@ -6,6 +6,7 @@ Python 是一门上手简单、功能强大、通用型的脚本编程语言。P
本教程来自[IPython Notebooks to learn Python](https://github.com/rajathkmp/Python-Lectures),将其中部分示例代码转化成Python3。关于Python的按照可以自行去网络上查找相关的资料,或者参考[安装Python环境](../tips/InstallPython.md)。 本教程来自[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) 1. [Basics](1_Basics.ipynb)
- Why Python, Zen of Python - Why Python, Zen of Python
- Variables, Operators, Built-in functions - Variables, Operators, Built-in functions


+ 0
- 1
README.md View File

@@ -11,7 +11,6 @@
1. [课程简介](CourseIntroduction.pdf) 1. [课程简介](CourseIntroduction.pdf)
2. [Python](0_python/) 2. [Python](0_python/)
- [Install Python](tips/InstallPython.md) - [Install Python](tips/InstallPython.md)
- [Introduction](0_python/0_Introduction.ipynb)
- [Python Basics](0_python/1_Basics.ipynb) - [Python Basics](0_python/1_Basics.ipynb)
- [Print Statement](0_python/2_Print_Statement.ipynb) - [Print Statement](0_python/2_Print_Statement.ipynb)
- [Data Structure 1](0_python/3_Data_Structure_1.ipynb) - [Data Structure 1](0_python/3_Data_Structure_1.ipynb)


Loading…
Cancel
Save