diff --git a/0_python/3_Data_Structure_1.ipynb b/0_python/3_Data_Structure_1.ipynb index 60aa0c0..1184e57 100644 --- a/0_python/3_Data_Structure_1.ipynb +++ b/0_python/3_Data_Structure_1.ipynb @@ -35,9 +35,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "a = []" @@ -155,10 +153,8 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": true - }, + "execution_count": 6, + "metadata": {}, "outputs": [], "source": [ "y = ['carrot','potato']" @@ -173,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -191,7 +187,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -200,7 +196,7 @@ "'orange'" ] }, - "execution_count": 6, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -310,12 +306,12 @@ "source": [ "索引只限于访问单个元素,而切片则是访问列表内的一系列数据。换句话说,`切片`返回的是一个列表。\n", "\n", - "切片是通过定义切片列表中需要的父列表中的第一个元素和最后一个元素的索引值来完成的。它被写成parentlist[a: b],其中`a`,`b`是父列表的索引值。如果`a`或`b`未定义,则认为该索引值是`a`未定义时的第一个值,以及`b`未定义时的最后一个值。" + "切片是通过定义切片列表中需要的父列表中的第一个元素和最后一个元素的索引值来完成的。它被写成`parentlist[a: b]`,其中`a`,`b`是父列表的索引值。如果`a`或`b`未定义,则认为该索引值是`a`未定义时的第一个值,以及`b`未定义时的最后一个值。" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -339,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -365,7 +361,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -374,7 +370,7 @@ "[2, 3, 6]" ] }, - "execution_count": 16, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -399,7 +395,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -408,7 +404,7 @@ "10" ] }, - "execution_count": 17, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -426,7 +422,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -442,7 +438,7 @@ "2" ] }, - "execution_count": 20, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -454,7 +450,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -463,7 +459,7 @@ "9" ] }, - "execution_count": 19, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -481,7 +477,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -490,7 +486,7 @@ "[1, 2, 3, 5, 4, 7]" ] }, - "execution_count": 21, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -508,10 +504,8 @@ }, { "cell_type": "code", - "execution_count": 22, - "metadata": { - "collapsed": true - }, + "execution_count": 19, + "metadata": {}, "outputs": [], "source": [ "names = ['Earth','Air','Fire','Water']" @@ -526,7 +520,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -535,7 +529,7 @@ "False" ] }, - "execution_count": 23, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -546,7 +540,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -555,7 +549,7 @@ "True" ] }, - "execution_count": 19, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -566,7 +560,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -575,7 +569,7 @@ "False" ] }, - "execution_count": 20, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -593,10 +587,8 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": true - }, + "execution_count": 23, + "metadata": {}, "outputs": [], "source": [ "mlist = ['bzaa','ds','nc','az','z','klm']" @@ -604,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -630,10 +622,8 @@ }, { "cell_type": "code", - "execution_count": 26, - "metadata": { - "collapsed": true - }, + "execution_count": 25, + "metadata": {}, "outputs": [], "source": [ "nlist = ['1','94','93','1000']" @@ -641,7 +631,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "metadata": {}, "outputs": [ { @@ -674,7 +664,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -705,7 +695,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -714,7 +704,7 @@ "['h', 'e', 'l', 'l', 'o']" ] }, - "execution_count": 29, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -732,10 +722,8 @@ }, { "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": true - }, + "execution_count": 29, + "metadata": {}, "outputs": [], "source": [ "lst = [1,1,4,8,7]" @@ -743,7 +731,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 30, "metadata": {}, "outputs": [ { @@ -768,7 +756,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -777,7 +765,7 @@ "3" ] }, - "execution_count": 32, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -795,10 +783,8 @@ }, { "cell_type": "code", - "execution_count": 33, - "metadata": { - "collapsed": true - }, + "execution_count": 32, + "metadata": {}, "outputs": [], "source": [ "lst1 = [5,4,2,8]" @@ -806,25 +792,15 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1, 1, 4, 8, 7, 1, [5, 4, 2, 8], [5, 4, 2, 8]]\n" + "[1, 1, 4, 8, 7, 1, [5, 4, 2, 8]]\n" ] - }, - { - "data": { - "text/plain": [ - "[1, 1, 4, 8, 7, 1, [5, 4, 2, 8], [5, 4, 2, 8], 5, 4, 2, 8]" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" } ], "source": [ @@ -841,14 +817,14 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1, 1, 4, 8, 7, 1, [5, 4, 2, 8], [5, 4, 2, 8], 5, 4, 2, 8]\n" + "[1, 1, 4, 8, 7, 1, [5, 4, 2, 8], 5, 4, 2, 8]\n" ] } ], @@ -866,7 +842,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 35, "metadata": {}, "outputs": [ { @@ -875,7 +851,7 @@ "0" ] }, - "execution_count": 37, + "execution_count": 35, "metadata": {}, "output_type": "execute_result" } @@ -886,7 +862,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -894,9 +870,9 @@ "evalue": "999 is not in list", "output_type": "error", "traceback": [ - "\u001b[0;31m------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0mTraceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m999\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mindex\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m999\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;31mValueError\u001b[0m: 999 is not in list" ] } @@ -914,17 +890,9 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 1, 4, 8, 7, 'name', 1, [5, 4, 2, 8], [5, 4, 2, 8], 5, 4, 2, 8]\n" - ] - } - ], + "outputs": [], "source": [ "lst.insert(5, 'name')\n", "print(lst)" @@ -939,17 +907,9 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 1, 4, 8, 7, 'Python', 1, [5, 4, 2, 8], [5, 4, 2, 8], 5, 4, 2, 8]\n" - ] - } - ], + "outputs": [], "source": [ "lst[5] = 'Python'\n", "print(lst)" @@ -964,20 +924,9 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[1, 1, 4, 8, 7, 'Python', 1, [5, 4, 2, 8], [5, 4, 2, 8], 5, 4, 2]" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "lst.pop()\n", "lst" @@ -992,47 +941,18 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "4" - ] - }, - "execution_count": 42, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "lst.pop(2)" ] }, { "cell_type": "code", - "execution_count": 43, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 1, 8, 7, 'Python', 1, [5, 4, 2, 8], [5, 4, 2, 8], 5, 4, 2]\n" - ] - }, - { - "data": { - "text/plain": [ - "4" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "print(lst)\n", "lst.pop(-2)" @@ -1040,17 +960,9 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 1, 8, 7, 'Python', 1, [5, 4, 2, 8], [5, 4, 2, 8], 5, 2]\n" - ] - } - ], + "outputs": [], "source": [ "print(lst)" ] @@ -1064,21 +976,9 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "ValueError", - "evalue": "list.remove(x): x not in list", - "output_type": "error", - "traceback": [ - "\u001b[0;31m------------------------------------------\u001b[0m", - "\u001b[0;31mValueError\u001b[0mTraceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Python'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlst\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mValueError\u001b[0m: list.remove(x): x not in list" - ] - } - ], + "outputs": [], "source": [ "lst.remove('Python')\n", "print(lst)" @@ -1093,18 +993,9 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, [5, 4, 2, 8], 5, 2]\n", - "[1, 5, 2]\n" - ] - } - ], + "outputs": [], "source": [ "print(lst)\n", "del lst[1]\n", @@ -1120,17 +1011,9 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2, 5, 1]\n" - ] - } - ], + "outputs": [], "source": [ "lst.reverse()\n", "print(lst)" @@ -1147,17 +1030,9 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[1, 4, 8, 8, 10]\n" - ] - } - ], + "outputs": [], "source": [ "lst = [1, 4, 8, 8, 10]\n", "lst.sort()\n", @@ -1173,21 +1048,9 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "must use keyword argument for key function", - "output_type": "error", - "traceback": [ - "\u001b[0;31m------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0mTraceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlst\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", - "\u001b[0;31mTypeError\u001b[0m: must use keyword argument for key function" - ] - } - ], + "outputs": [], "source": [ "lst.sort(reverse=True)\n", "print(lst)" @@ -1202,18 +1065,9 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['apple', 'orange', 'peach']\n", - "['peach', 'orange', 'apple']\n" - ] - } - ], + "outputs": [], "source": [ "names = ['apple', 'orange', 'peach']\n", "names.sort()\n", @@ -1231,18 +1085,9 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['peach', 'apple', 'orange']\n", - "['orange', 'peach', 'apple']\n" - ] - } - ], + "outputs": [], "source": [ "names.sort(key=len)\n", "print(names)\n", @@ -1266,10 +1111,8 @@ }, { "cell_type": "code", - "execution_count": 59, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "lista= [2,1,4,3]" @@ -1277,17 +1120,9 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2, 1, 4, 3]\n" - ] - } - ], + "outputs": [], "source": [ "listb = lista # 对象赋值\n", "print(listb)" @@ -1302,18 +1137,9 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2, 1, 4]\n", - "[2, 1, 4, 9]\n" - ] - } - ], + "outputs": [], "source": [ "lista.pop()\n", "print(lista)\n", @@ -1323,17 +1149,9 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2, 1, 4, 9]\n" - ] - } - ], + "outputs": [], "source": [ "print(listb)" ] @@ -1344,15 +1162,13 @@ "source": [ "虽然没有对listb执行任何操作,但它也发生了变化。这是因为您将lista、listb指向相同的内存空间。那么如何解决这个问题呢?\n", "\n", - "如果您还记得,在切片中我们已经看到parentlist[a:b]从父列表返回一个起始索引a和结束索引b的列表,如果a和b没有被提及,那么默认情况下它会考虑第一个和最后一个元素。我们在这里使用相同的概念。通过这样做,我们将lista的数据作为变量分配给listb。" + "在切片中我们已经看到parentlist[a:b]从父列表返回一个起始索引a和结束索引b的列表,如果a和b没有被提及,那么默认情况下它会包含第一个到最后一个元素。我们在这里使用相同的概念。通过这样做,我们将lista的数据作为变量分配给listb。" ] }, { "cell_type": "code", - "execution_count": 63, - "metadata": { - "collapsed": true - }, + "execution_count": null, + "metadata": {}, "outputs": [], "source": [ "lista = [2,1,4,3]" @@ -1360,17 +1176,9 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2, 1, 4, 3]\n" - ] - } - ], + "outputs": [], "source": [ "listb = lista[:]\n", "print(listb)" @@ -1378,18 +1186,9 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2, 1, 4]\n", - "[2, 1, 4, 9]\n" - ] - } - ], + "outputs": [], "source": [ "lista.pop()\n", "print(lista)\n", @@ -1399,17 +1198,9 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[2, 1, 4, 3]\n" - ] - } - ], + "outputs": [], "source": [ "print(listb)" ] @@ -1432,34 +1223,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "元组与列表相似,但唯一大的区别是列表中的元素可以更改,而元组中的元素不能更改。为了更好地理解,请回忆**divmod()** 函数。" + "元组与列表相似,但唯一大的区别是列表中的元素可以更改,而**元组中的元素不能更改**。为了更好地理解,请回忆**divmod()** 函数。" ] }, { "cell_type": "code", - "execution_count": 68, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(3, 1)\n", - "\n" - ] - }, - { - "ename": "TypeError", - "evalue": "'tuple' object does not support item assignment", - "output_type": "error", - "traceback": [ - "\u001b[0;31m------------------------------------------\u001b[0m", - "\u001b[0;31mTypeError\u001b[0mTraceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxyz\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mxyz\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mxyz\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" - ] - } - ], + "outputs": [], "source": [ "xyz = divmod(10,3)\n", "print(xyz)\n", @@ -1483,10 +1254,8 @@ }, { "cell_type": "code", - "execution_count": 69, - "metadata": { - "collapsed": true - }, + "execution_count": 37, + "metadata": {}, "outputs": [], "source": [ "tup = ()\n", @@ -1502,7 +1271,7 @@ }, { "cell_type": "code", - "execution_count": 74, + "execution_count": 38, "metadata": {}, "outputs": [ { @@ -1511,7 +1280,7 @@ "(27,)" ] }, - "execution_count": 74, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } @@ -1529,7 +1298,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -1538,7 +1307,7 @@ "(27, 27)" ] }, - "execution_count": 75, + "execution_count": 39, "metadata": {}, "output_type": "execute_result" } @@ -1556,7 +1325,7 @@ }, { "cell_type": "code", - "execution_count": 76, + "execution_count": 40, "metadata": { "scrolled": true }, @@ -1586,7 +1355,7 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1613,10 +1382,8 @@ }, { "cell_type": "code", - "execution_count": 80, - "metadata": { - "collapsed": true - }, + "execution_count": 42, + "metadata": {}, "outputs": [], "source": [ "(a,b,c)= ('alpha','beta','gamma')" @@ -1624,7 +1391,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 43, "metadata": {}, "outputs": [ { @@ -1641,7 +1408,16 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "(c, b, a) = (a, b, c)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, "metadata": {}, "outputs": [ { @@ -1673,7 +1449,7 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -1682,7 +1458,7 @@ "3" ] }, - "execution_count": 82, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } @@ -1700,7 +1476,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -1709,7 +1485,7 @@ "1" ] }, - "execution_count": 83, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -1736,7 +1512,7 @@ }, { "cell_type": "code", - "execution_count": 85, + "execution_count": 48, "metadata": {}, "outputs": [ { @@ -1754,7 +1530,7 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 49, "metadata": {}, "outputs": [ { @@ -1772,7 +1548,7 @@ }, { "cell_type": "code", - "execution_count": 88, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -1804,10 +1580,8 @@ }, { "cell_type": "code", - "execution_count": 89, - "metadata": { - "collapsed": true - }, + "execution_count": 51, + "metadata": {}, "outputs": [], "source": [ "set1 = set([1,2,3])" @@ -1815,10 +1589,8 @@ }, { "cell_type": "code", - "execution_count": 90, - "metadata": { - "collapsed": true - }, + "execution_count": 52, + "metadata": {}, "outputs": [], "source": [ "set2 = set([2,3,4,5])" @@ -1828,12 +1600,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**union( )** 函数返回一个集合,该集合包含两个集合的所有元素,但是没有重复。" + "**union( )** 函数返回一个并集合,该集合包含两个集合的所有元素,但是没有重复。" ] }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 53, "metadata": {}, "outputs": [ { @@ -1842,7 +1614,7 @@ "{1, 2, 3, 4, 5}" ] }, - "execution_count": 91, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -1860,7 +1632,7 @@ }, { "cell_type": "code", - "execution_count": 92, + "execution_count": 54, "metadata": {}, "outputs": [ { @@ -1876,7 +1648,7 @@ "{0, 1, 2, 3}" ] }, - "execution_count": 92, + "execution_count": 54, "metadata": {}, "output_type": "execute_result" } @@ -1891,12 +1663,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**intersection( )** 函数输出一个集合,该集合包含两个集合中的所有元素。" + "**intersection( )** 函数输出一个交集合,该集合包含两个集合中的所有元素。" ] }, { "cell_type": "code", - "execution_count": 93, + "execution_count": 55, "metadata": {}, "outputs": [ { @@ -1905,7 +1677,7 @@ "{2, 3}" ] }, - "execution_count": 93, + "execution_count": 55, "metadata": {}, "output_type": "execute_result" } @@ -1923,7 +1695,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 56, "metadata": {}, "outputs": [ { @@ -1940,7 +1712,7 @@ "{0, 1}" ] }, - "execution_count": 94, + "execution_count": 56, "metadata": {}, "output_type": "execute_result" } @@ -1960,10 +1732,8 @@ }, { "cell_type": "code", - "execution_count": 115, - "metadata": { - "collapsed": true - }, + "execution_count": 57, + "metadata": {}, "outputs": [], "source": [ "set1=set([10, 9, 1, 2, 4])" @@ -1971,14 +1741,14 @@ }, { "cell_type": "code", - "execution_count": 113, + "execution_count": 58, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "set()\n" + "{2, 4, 9, 10}\n" ] } ], @@ -1996,16 +1766,16 @@ }, { "cell_type": "code", - "execution_count": 116, + "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{1, 4, 9, 10}" + "{4, 9, 10}" ] }, - "execution_count": 116, + "execution_count": 59, "metadata": {}, "output_type": "execute_result" } @@ -2024,7 +1794,7 @@ }, { "cell_type": "code", - "execution_count": 117, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -2033,7 +1803,7 @@ "set()" ] }, - "execution_count": 117, + "execution_count": 60, "metadata": {}, "output_type": "execute_result" } diff --git a/0_python/4_Data_Structure_2.ipynb b/0_python/4_Data_Structure_2.ipynb index 56f5f02..5ef6ff7 100644 --- a/0_python/4_Data_Structure_2.ipynb +++ b/0_python/4_Data_Structure_2.ipynb @@ -91,7 +91,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**find( )** 函数返回要在字符串中找到的给定数据的索引值。如果没有找到它,它返回 **-1**。记住不要将返回的-1与反向索引值混淆。" + "**find( )** 函数返回要在字符串中找到的给定数据的索引值。如果没有找到它,它返回 **-1**。请注意不要将返回的-1与反向索引值混淆。" ] }, { @@ -1198,7 +1198,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/0_python/5_Control_Flow.ipynb b/0_python/5_Control_Flow.ipynb index deb07a3..5ac5862 100644 --- a/0_python/5_Control_Flow.ipynb +++ b/0_python/5_Control_Flow.ipynb @@ -441,7 +441,7 @@ " if i>4:\n", " print(\"The end.\")\n", " continue\n", - " elif i<7:\n", + " if i<7:\n", " print(i)" ] }, @@ -551,16 +551,16 @@ { "data": { "text/plain": [ - "{'108': 108,\n", + "{'27': 27,\n", + " '54': 54,\n", + " '81': 81,\n", + " '108': 108,\n", " '135': 135,\n", " '162': 162,\n", " '189': 189,\n", " '216': 216,\n", " '243': 243,\n", - " '27': 27,\n", - " '270': 270,\n", - " '54': 54,\n", - " '81': 81}" + " '270': 270}" ] }, "execution_count": 15, @@ -636,7 +636,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/0_python/6_Function.ipynb b/0_python/6_Function.ipynb index b81d8e0..28350a1 100644 --- a/0_python/6_Function.ipynb +++ b/0_python/6_Function.ipynb @@ -11,7 +11,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "在大部分时候,在一个算法中,需要重复执行一组语句,如果每次都重复写出来,不仅乏味而且编程效率比较低,降低程序的可读性。为了将重复的执行抽象出来,可使用函数将一组操作封装成一个整体,给一个名称和参数列表作为可变量的输入。Python中函数的定义为:" + "在大部分时候,在一个算法中,需要重复执行一组语句,如果每次都重复写出来,不仅乏味而且编程效率比较低,降低程序的可读性。为了将重复的执行抽象出来,可使用函数将一组操作封装成一个整体,给一个名称和参数列表作为可变量的输入。\n", + "\n", + "Python中函数的定义为:" ] }, { @@ -68,9 +70,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def first_func():\n", @@ -110,9 +110,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def first_func(username):\n", @@ -129,7 +127,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "Please enter your name : Python\n" + "Please enter your name : Jack\n" ] } ], @@ -141,7 +139,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "名称“Willam”实际上存储在name1中。我们将这个变量传递给函数**firstfunc()** 作为变量username,因为它是为这个函数定义的变量。即name1作为用户名传递。" + "名称“Willam”实际上存储在name1中。我们将这个变量传递给函数**first_func()** 作为变量username,因为它是为这个函数定义的变量。即name1作为用户名传递。" ] }, { @@ -153,8 +151,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "Hey Python!\n", - "Python, How do you do?\n" + "Hey Jack!\n", + "Jack, How do you do?\n" ] } ], @@ -172,9 +170,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def first_func(username):\n", @@ -221,9 +217,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def times(x,y):\n", @@ -273,9 +267,7 @@ { "cell_type": "code", "execution_count": 11, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def times(x,y):\n", @@ -332,9 +324,7 @@ { "cell_type": "code", "execution_count": 14, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "times?" @@ -350,9 +340,7 @@ { "cell_type": "code", "execution_count": 15, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "eglist = [10,50,30,12,6,8,100]" @@ -361,9 +349,7 @@ { "cell_type": "code", "execution_count": 16, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def egfunc(eglist):\n", @@ -436,10 +422,8 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": { - "collapsed": true - }, + "execution_count": 19, + "metadata": {}, "outputs": [], "source": [ "def implicit_add(x, addnumber=3):\n", @@ -462,7 +446,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 20, "metadata": {}, "outputs": [ { @@ -471,7 +455,7 @@ "7" ] }, - "execution_count": 21, + "execution_count": 20, "metadata": {}, "output_type": "execute_result" } @@ -489,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -498,7 +482,7 @@ "8" ] }, - "execution_count": 22, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -509,7 +493,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 22, "metadata": {}, "outputs": [ { @@ -518,7 +502,7 @@ "11" ] }, - "execution_count": 23, + "execution_count": 22, "metadata": {}, "output_type": "execute_result" } @@ -543,10 +527,8 @@ }, { "cell_type": "code", - "execution_count": 24, - "metadata": { - "collapsed": true - }, + "execution_count": 23, + "metadata": {}, "outputs": [], "source": [ "def add_n(*args):\n", @@ -567,7 +549,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 24, "metadata": {}, "outputs": [ { @@ -583,7 +565,7 @@ "15" ] }, - "execution_count": 25, + "execution_count": 24, "metadata": {}, "output_type": "execute_result" } @@ -594,7 +576,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 25, "metadata": {}, "outputs": [ { @@ -610,7 +592,7 @@ "6" ] }, - "execution_count": 26, + "execution_count": 25, "metadata": {}, "output_type": "execute_result" } @@ -628,14 +610,14 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[30, 10, 20]\n" + "[10, 20, 30]\n" ] }, { @@ -644,7 +626,7 @@ "60" ] }, - "execution_count": 27, + "execution_count": 26, "metadata": {}, "output_type": "execute_result" } @@ -677,10 +659,8 @@ }, { "cell_type": "code", - "execution_count": 28, - "metadata": { - "collapsed": true - }, + "execution_count": 27, + "metadata": {}, "outputs": [], "source": [ "eg1 = [1,2,3,4,5]" @@ -695,10 +675,8 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": { - "collapsed": true - }, + "execution_count": 28, + "metadata": {}, "outputs": [], "source": [ "def egfunc1():\n", @@ -717,7 +695,7 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -763,10 +741,8 @@ }, { "cell_type": "code", - "execution_count": 31, - "metadata": { - "collapsed": true - }, + "execution_count": 30, + "metadata": {}, "outputs": [], "source": [ "z = lambda x: x * x" @@ -774,7 +750,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 31, "metadata": {}, "outputs": [ { @@ -783,7 +759,7 @@ "64" ] }, - "execution_count": 32, + "execution_count": 31, "metadata": {}, "output_type": "execute_result" } @@ -794,7 +770,7 @@ }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -803,7 +779,7 @@ "(6, 8)" ] }, - "execution_count": 33, + "execution_count": 32, "metadata": {}, "output_type": "execute_result" } @@ -815,7 +791,7 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -824,7 +800,7 @@ "function" ] }, - "execution_count": 34, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -835,7 +811,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -844,7 +820,7 @@ "function" ] }, - "execution_count": 35, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -872,10 +848,8 @@ }, { "cell_type": "code", - "execution_count": 36, - "metadata": { - "collapsed": true - }, + "execution_count": 35, + "metadata": {}, "outputs": [], "source": [ "list1 = [1,2,3,4,5,6,7,8,9]" @@ -883,7 +857,7 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -901,7 +875,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -926,10 +900,8 @@ }, { "cell_type": "code", - "execution_count": 39, - "metadata": { - "collapsed": true - }, + "execution_count": 38, + "metadata": {}, "outputs": [], "source": [ "list2 = [9,8,7,6,5,4,3,2,1]" @@ -937,7 +909,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": 39, "metadata": {}, "outputs": [ { @@ -962,14 +934,14 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 40, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\n" + "\n" ] } ], @@ -994,10 +966,8 @@ }, { "cell_type": "code", - "execution_count": 42, - "metadata": { - "collapsed": true - }, + "execution_count": 41, + "metadata": {}, "outputs": [], "source": [ "list1 = [1,2,3,4,5,6,7,8,9]" @@ -1012,7 +982,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -1037,16 +1007,16 @@ }, { "cell_type": "code", - "execution_count": 44, + "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 44, + "execution_count": 43, "metadata": {}, "output_type": "execute_result" } @@ -1064,16 +1034,16 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 44, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "" + "" ] }, - "execution_count": 45, + "execution_count": 44, "metadata": {}, "output_type": "execute_result" } @@ -1099,7 +1069,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.9" } }, "nbformat": 4, diff --git a/0_python/7_Class.ipynb b/0_python/7_Class.ipynb index 78cf535..36dce8b 100644 --- a/0_python/7_Class.ipynb +++ b/0_python/7_Class.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# 1. 类" + "# 类" ] }, { @@ -18,7 +18,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "类声明如下" + "类声明如下:" ] }, { @@ -35,9 +35,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "# 一个最简单的类\n", @@ -49,7 +47,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "**pass** 在python中意味着什么都不做。 " + "**pass** 在Python中意味着什么都不做。 " ] }, { @@ -62,9 +60,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "egclass = FirstClass()" @@ -92,7 +88,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -101,7 +97,7 @@ "type" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -142,10 +138,8 @@ }, { "cell_type": "code", - "execution_count": 1, - "metadata": { - "collapsed": true - }, + "execution_count": 5, + "metadata": {}, "outputs": [], "source": [ "class FirstClass:\n", @@ -165,10 +159,8 @@ }, { "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": true - }, + "execution_count": 6, + "metadata": {}, "outputs": [], "source": [ "eg1 = FirstClass('one',1)\n", @@ -177,7 +169,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -205,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 8, "metadata": { "scrolled": false }, @@ -225,6 +217,7 @@ " '__gt__',\n", " '__hash__',\n", " '__init__',\n", + " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", @@ -241,7 +234,7 @@ " 'class_var']" ] }, - "execution_count": 4, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -252,7 +245,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -261,7 +254,7 @@ "'My first class'" ] }, - "execution_count": 5, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -279,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -297,6 +290,7 @@ " '__gt__',\n", " '__hash__',\n", " '__init__',\n", + " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", @@ -315,7 +309,7 @@ " 'value']" ] }, - "execution_count": 6, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } @@ -333,10 +327,8 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": { - "collapsed": true - }, + "execution_count": 11, + "metadata": {}, "outputs": [], "source": [ "class FirstClass:\n", @@ -354,10 +346,8 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": { - "collapsed": true - }, + "execution_count": 12, + "metadata": {}, "outputs": [], "source": [ "eg1 = FirstClass('one',1)\n", @@ -366,7 +356,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -376,7 +366,7 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meg1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0meg1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msymbol\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meg2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0meg2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msymbol\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meg1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0meg1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msymbol\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meg2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0meg2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msymbol\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mAttributeError\u001b[0m: 'FirstClass' object has no attribute 'name'" ] } @@ -395,7 +385,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 15, "metadata": {}, "outputs": [ { @@ -413,6 +403,7 @@ " '__gt__',\n", " '__hash__',\n", " '__init__',\n", + " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", @@ -430,7 +421,7 @@ " 'v']" ] }, - "execution_count": 10, + "execution_count": 15, "metadata": {}, "output_type": "execute_result" } @@ -441,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -473,10 +464,8 @@ }, { "cell_type": "code", - "execution_count": 12, - "metadata": { - "collapsed": true - }, + "execution_count": 17, + "metadata": {}, "outputs": [], "source": [ "class FirstClass:\n", @@ -487,10 +476,8 @@ }, { "cell_type": "code", - "execution_count": 13, - "metadata": { - "collapsed": true - }, + "execution_count": 18, + "metadata": {}, "outputs": [], "source": [ "eg1 = FirstClass('one',1)\n", @@ -499,7 +486,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -525,10 +512,8 @@ }, { "cell_type": "code", - "execution_count": 15, - "metadata": { - "collapsed": true - }, + "execution_count": 20, + "metadata": {}, "outputs": [], "source": [ "eg1.cube = 1\n", @@ -537,7 +522,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 21, "metadata": {}, "outputs": [ { @@ -555,6 +540,7 @@ " '__gt__',\n", " '__hash__',\n", " '__init__',\n", + " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", @@ -573,7 +559,7 @@ " 'v']" ] }, - "execution_count": 16, + "execution_count": 21, "metadata": {}, "output_type": "execute_result" } @@ -597,10 +583,8 @@ }, { "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": true - }, + "execution_count": 22, + "metadata": {}, "outputs": [], "source": [ "class FirstClass:\n", @@ -619,7 +603,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 23, "metadata": {}, "outputs": [ { @@ -639,18 +623,14 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 24, "metadata": {}, "outputs": [ { - "ename": "AttributeError", - "evalue": "'FirstClass' object has no attribute 'test'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meg3\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtest\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0meg3\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m: 'FirstClass' object has no attribute 'test'" + "name": "stdout", + "output_type": "stream", + "text": [ + "test Three\n" ] } ], @@ -667,10 +647,8 @@ }, { "cell_type": "code", - "execution_count": 19, - "metadata": { - "collapsed": true - }, + "execution_count": 25, + "metadata": {}, "outputs": [], "source": [ "class FirstClass:\n", @@ -687,10 +665,8 @@ }, { "cell_type": "code", - "execution_count": 20, - "metadata": { - "collapsed": true - }, + "execution_count": 26, + "metadata": {}, "outputs": [], "source": [ "eg4 = FirstClass('Five',5)" @@ -698,7 +674,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -717,7 +693,7 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -726,7 +702,7 @@ "10" ] }, - "execution_count": 22, + "execution_count": 28, "metadata": {}, "output_type": "execute_result" } @@ -744,7 +720,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 29, "metadata": {}, "outputs": [ { @@ -753,7 +729,7 @@ "10" ] }, - "execution_count": 23, + "execution_count": 29, "metadata": {}, "output_type": "execute_result" } @@ -785,10 +761,8 @@ }, { "cell_type": "code", - "execution_count": 25, - "metadata": { - "collapsed": true - }, + "execution_count": 30, + "metadata": {}, "outputs": [], "source": [ "class Person:\n", @@ -802,7 +776,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -811,7 +785,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 32, "metadata": {}, "outputs": [ { @@ -828,7 +802,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 33, "metadata": {}, "outputs": [ { @@ -846,6 +820,7 @@ " '__gt__',\n", " '__hash__',\n", " '__init__',\n", + " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", @@ -862,7 +837,7 @@ " 'salary']" ] }, - "execution_count": 28, + "execution_count": 33, "metadata": {}, "output_type": "execute_result" } @@ -880,10 +855,8 @@ }, { "cell_type": "code", - "execution_count": 29, - "metadata": { - "collapsed": true - }, + "execution_count": 34, + "metadata": {}, "outputs": [], "source": [ "class Artist:\n", @@ -900,10 +873,8 @@ }, { "cell_type": "code", - "execution_count": 30, - "metadata": { - "collapsed": true - }, + "execution_count": 35, + "metadata": {}, "outputs": [], "source": [ "b = Artist('Nick',20)" @@ -911,7 +882,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 36, "metadata": {}, "outputs": [ { @@ -930,7 +901,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 37, "metadata": {}, "outputs": [ { @@ -948,6 +919,7 @@ " '__gt__',\n", " '__hash__',\n", " '__init__',\n", + " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", @@ -965,7 +937,7 @@ " 'salary']" ] }, - "execution_count": 32, + "execution_count": 37, "metadata": {}, "output_type": "execute_result" } @@ -983,10 +955,8 @@ }, { "cell_type": "code", - "execution_count": 33, - "metadata": { - "collapsed": true - }, + "execution_count": 38, + "metadata": {}, "outputs": [], "source": [ "class Artist(Person):\n", @@ -997,10 +967,8 @@ }, { "cell_type": "code", - "execution_count": 34, - "metadata": { - "collapsed": true - }, + "execution_count": 39, + "metadata": {}, "outputs": [], "source": [ "c = Artist('Tom',21)" @@ -1008,7 +976,7 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -1026,6 +994,7 @@ " '__gt__',\n", " '__hash__',\n", " '__init__',\n", + " '__init_subclass__',\n", " '__le__',\n", " '__lt__',\n", " '__module__',\n", @@ -1043,7 +1012,7 @@ " 'salary']" ] }, - "execution_count": 35, + "execution_count": 40, "metadata": {}, "output_type": "execute_result" } @@ -1054,7 +1023,7 @@ }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 41, "metadata": {}, "outputs": [ { @@ -1080,10 +1049,8 @@ }, { "cell_type": "code", - "execution_count": 37, - "metadata": { - "collapsed": true - }, + "execution_count": 42, + "metadata": {}, "outputs": [], "source": [ "class Artist(Person):\n", @@ -1098,10 +1065,8 @@ }, { "cell_type": "code", - "execution_count": 38, - "metadata": { - "collapsed": true - }, + "execution_count": 43, + "metadata": {}, "outputs": [], "source": [ "c = Artist('Tom',21)" @@ -1109,7 +1074,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 44, "metadata": {}, "outputs": [ { @@ -1136,10 +1101,8 @@ }, { "cell_type": "code", - "execution_count": 43, - "metadata": { - "collapsed": true - }, + "execution_count": 45, + "metadata": {}, "outputs": [], "source": [ "class NotSure:\n", @@ -1149,10 +1112,8 @@ }, { "cell_type": "code", - "execution_count": 44, - "metadata": { - "collapsed": true - }, + "execution_count": 46, + "metadata": {}, "outputs": [], "source": [ "yz = NotSure('I', 'Do' , 'Not', 'Know', 'What', 'To','Type')" @@ -1160,7 +1121,7 @@ }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 47, "metadata": {}, "outputs": [ { @@ -1169,7 +1130,7 @@ "'I Do Not Know What To Type'" ] }, - "execution_count": 45, + "execution_count": 47, "metadata": {}, "output_type": "execute_result" } @@ -1189,9 +1150,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "为了学好Python,仅仅看教程是不够的,需要做大量的练习题,可以使用教程里列的练习题,也可以自己找各个方面的练习题。\n", + "为了学好Python,仅仅看教程是不够的,需要做大量的练习题。可以使用教程里所列的练习题,也可以自己找各个方面的练习题。\n", "\n", - "* 编程比较重要的培养编程思维,如果抄别人写好的代码,发现不了Python的窍门、技巧,因此需要独立自主完成编程练习,也可以给自己出一些小项目,病解决它们,你还可以在任何编程竞赛平台上提交问题求解。\n", + "* 编程比较重要的培养编程思维,如果抄别人写好的代码,发现不了Python的窍门、技巧,因此需要独立自主完成编程练习,也可以给自己出一些小项目,并解决它们。\n", "* 你编写的代码越多,你发现的越多,你就越开始欣赏这门语言。\n", "* 强烈建议把[《Python作业》](https://gitee.com/pi-lab/machinelearning_homework/blob/master/homework_01_python/README.md)完成\n", "* 在完成基本的编程习题之后,可以在[《其他编程练习》](https://gitee.com/pi-lab/machinelearning_homework/blob/master/homework_01_python/README.md#references)里面找一些练习题或者项目做一下。\n", @@ -1231,7 +1192,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.5.4" + "version": "3.7.9" } }, "nbformat": 4,