Browse Source

update contents for 0_python

pull/2/MERGE
Geoff 4 years ago
parent
commit
0f8c52c119
11 changed files with 386 additions and 348 deletions
  1. +46
    -46
      0_python/1_Basics.ipynb
  2. +24
    -24
      0_python/2_Print_Statement.ipynb
  3. +82
    -82
      0_python/3_Data_Structure_1.ipynb
  4. +45
    -45
      0_python/4_Data_Structure_2.ipynb
  5. +12
    -12
      0_python/5_Control_Flow.ipynb
  6. +37
    -37
      0_python/6_Function.ipynb
  7. +96
    -65
      0_python/7_Class.ipynb
  8. +3
    -3
      0_python/7_Class_EN.ipynb
  9. +1
    -1
      1_numpy_matplotlib_scipy_sympy/1-numpy_tutorial.ipynb
  10. +11
    -4
      1_numpy_matplotlib_scipy_sympy/2-matplotlib_simple_tutorial.ipynb
  11. +29
    -29
      1_numpy_matplotlib_scipy_sympy/5-sympy_tutorial.ipynb

+ 46
- 46
0_python/1_Basics.ipynb View File

@@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Python Basic"
"# Python 基础"
] ]
}, },
{ {
@@ -20,7 +20,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 1. import & Zen of Python\n"
"## 1. 导入和Python之禅\n"
] ]
}, },
{ {
@@ -95,14 +95,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2. Variables"
"## 2. 变量"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"A name that is used to denote something or a value is called a variable. In python, variables can be declared and values can be assigned to it as follows,"
"用于表示某物或值的名称称为变量。在python中,可以声明变量并为其赋值,如下所示:"
] ]
}, },
{ {
@@ -137,12 +137,12 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Multiple variables can be assigned with the same value."
"多变量可以被赋予相同的名字。"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -151,7 +151,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -170,14 +170,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 3. Operators"
"## 3. 运算符"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 3.1 Arithmetic Operators"
"### 3.1 算数运算符"
] ]
}, },
{ {
@@ -197,7 +197,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -206,7 +206,7 @@
"3" "3"
] ]
}, },
"execution_count": 10,
"execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -217,7 +217,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -226,7 +226,7 @@
"1" "1"
] ]
}, },
"execution_count": 11,
"execution_count": 5,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -237,7 +237,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12,
"execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -246,7 +246,7 @@
"2" "2"
] ]
}, },
"execution_count": 12,
"execution_count": 6,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -257,7 +257,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 8,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -266,7 +266,7 @@
"0.5" "0.5"
] ]
}, },
"execution_count": 5,
"execution_count": 8,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -279,7 +279,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"0? This is because both the numerator and denominator are integers but the result is a float value hence an integer value is returned. By changing either the numerator or the denominator to float, correct answer can be obtained."
"0?这是由于分子和分母都是整数,但是结果是一个浮点数,因此 返回整数值,通过将分子或分母更改为浮点型,可以获得正确的答案。"
] ]
}, },
{ {
@@ -346,7 +346,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Floor division is nothing but converting the result so obtained to the nearest integer."
"地板除法就是将这样得到的结果转换成最接近的整数。"
] ]
}, },
{ {
@@ -373,7 +373,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 3.2 Relational Operators"
"### 3.2 关系运算符"
] ]
}, },
{ {
@@ -392,7 +392,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -401,7 +401,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -410,7 +410,7 @@
"True" "True"
] ]
}, },
"execution_count": 7,
"execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -421,7 +421,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8,
"execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -430,7 +430,7 @@
"False" "False"
] ]
}, },
"execution_count": 8,
"execution_count": 11,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -443,7 +443,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 3.3 Bitwise Operators"
"### 3.3 位运算符"
] ]
}, },
{ {
@@ -515,14 +515,14 @@
"source": [ "source": [
"0000 0101 -> 5 \n", "0000 0101 -> 5 \n",
"\n", "\n",
"Shifting the digits by 1 to the right and zero padding\n",
"将数字向右移1并填充0。\n",
"\n", "\n",
"0000 0010 -> 2" "0000 0010 -> 2"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 24,
"execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -531,7 +531,7 @@
"10" "10"
] ]
}, },
"execution_count": 24,
"execution_count": 12,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -546,7 +546,7 @@
"source": [ "source": [
"0000 0101 -> 5 \n", "0000 0101 -> 5 \n",
"\n", "\n",
"Shifting the digits by 1 to the left and zero padding\n",
"将数字做移1并填充0。\n",
"\n", "\n",
"0000 1010 -> 10" "0000 1010 -> 10"
] ]
@@ -555,28 +555,28 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 4. Built-in Functions"
"## 4. 内置函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Python comes loaded with pre-built functions"
"Python带有预先构建的函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 4.1 Conversion from one system to another"
"### 4.1 从一个系统到另一个系统的转换"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Conversion from hexadecimal to decimal is done by adding prefix **0x** to the hexadecimal value or vice versa by using built in **hex( )**, Octal to decimal by adding prefix **0** to the octal value or vice versa by using built in function **oct( )**."
"从十六进制到十进制的转换是通过向十六进制值添加前缀**0x**来完成的,反之亦然,使用内置的**hex()**,通过在八进制值中添加前缀**0**,从八进制到十进制,或者通过使用内建函数**oct()** 从八进制到十进制。"
] ]
}, },
{ {
@@ -643,7 +643,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**int( )** accepts two values when used for conversion, one is the value in a different number system and the other is its base. Note that input number in the different number system should be of string type."
"**int( )** 在用于转换时接受两个值,一个是不同数字系统中的值,另一个是它的基数。注意,不同数字系统中的输入数字应该是字符串类型。"
] ]
}, },
{ {
@@ -671,7 +671,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**int( )** can also be used to get only the integer value of a float number or can be used to convert a number which is of type string to integer format. Similarly, the function **str( )** can be used to convert the integer back to string format"
"**int( )** 也可用于仅获取浮点数的整数值,或用于将字符串类型的数字转换为整数格式。相似地,函数 **str( )** 可以被用来将整形转化为字符串类型。"
] ]
}, },
{ {
@@ -697,7 +697,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Also note that function **bin( )** is used for binary and **float( )** for decimal/float values. **chr( )** is used for converting ASCII to its alphabet equivalent, **ord( )** is used for the other way round."
"同样需要注意的是 **bin( )** 被用作二进制而 **float( )** 被用作十进制、浮点值。**chr( )** 用于将ASCII码转换为等效的字母表,**ord( )** 被反过来使用。"
] ]
}, },
{ {
@@ -744,14 +744,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 4.2 Simplifying Arithmetic Operations"
"### 4.2 简化算术运算"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**round( )** function rounds the input value to a specified number of places or to the nearest integer. "
"**round( )** 函数将输入值四舍五入到指定的位数或最接近的整数。"
] ]
}, },
{ {
@@ -779,7 +779,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**complex( )** is used to define a complex number and **abs( )** outputs the absolute value of the same."
"**complex( )** 被用来定义一个复数 **abs( )** 输出相同的绝对值。"
] ]
}, },
{ {
@@ -804,7 +804,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**divmod(x,y)** outputs the quotient and the remainder in a tuple(you will be learning about it in the further chapters) in the format (quotient, remainder). "
"**divmod(x,y)** 输出商和余数在元组(你将在后面的章节学习)的格式(商,余数)。"
] ]
}, },
{ {
@@ -831,7 +831,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**isinstance( )** returns True, if the first argument is an instance of that class. Multiple classes can also be checked at once."
"如果第一个参数是该类的实例,**isinstance( )** 则返回True。还可以同时检查多个类。"
] ]
}, },
{ {
@@ -889,7 +889,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**pow(x,y,z)** can be used to find the power $x^y$ also the mod of the resulting value with the third specified number can be found i.e. : ($x^y$ % z)."
"**pow(x,y,z)** 可以被用来找到幂函数$x^y$也可以找到第三个指定数字的mod值,即:($x^y$ % z)。"
] ]
}, },
{ {
@@ -915,7 +915,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**range( )** function outputs the integers of the specified range. It can also be used to generate a series by specifying the difference between the two numbers within a particular range. The elements are returned in a list (will be discussing in detail later.)"
"**range( )** 函数输出指定范围的整数。它还可以用于通过指定特定范围内的两个数字之间的差来生成一个序列。元素以列表的形式返回(稍后将详细讨论)。"
] ]
}, },
{ {
@@ -943,14 +943,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 4.3 Accepting User Inputs"
"### 4.3 接受用户输入"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**input( )** accepts input and stores it as a string. "
"**input( )** 接受输入并以字符串的形式保存。"
] ]
}, },
{ {


+ 24
- 24
0_python/2_Print_Statement.ipynb View File

@@ -4,14 +4,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Print Statement"
"# Print 语句"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The **print** statement can be used in the following different ways :\n",
"**print** 语句可以用下列不同的方式使用。\n",
"\n", "\n",
" - print(\"Hello World\")\n", " - print(\"Hello World\")\n",
" - print(\"Hello\", <Variable Containing the String>)\n", " - print(\"Hello\", <Variable Containing the String>)\n",
@@ -40,9 +40,9 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In Python, single, double and triple quotes are used to denote a string.\n",
"Most use single quotes when declaring a single character. \n",
"Double quotes when declaring a line and triple quotes when declaring a paragraph/multiple lines."
"在Python中,单引号、双引号和三引号用于表示字符串。\n",
"大部分单引号用于声明一个字符。\n",
"声明一行时使用双引号,声明段落/多行时使用三引号。"
] ]
}, },
{ {
@@ -87,12 +87,12 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Strings can be assigned to variable say _string1_ and _string2_ which can called when using the print statement."
"字符串可以分配给变量 _string1_ 和string2,使用print语句时可以调用。"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"metadata": { "metadata": {
"scrolled": true "scrolled": true
}, },
@@ -118,7 +118,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"String concatenation is the \"addition\" of two strings. Observe that while concatenating there will be no space between the strings."
"字符串连接是两个字符串的“加法”。注意,在连接时,字符串之间不会有空格。"
] ]
}, },
{ {
@@ -142,7 +142,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**%s** is used to refer to a variable which contains a string."
"**%s** 用于引用包含字符串的变量。"
] ]
}, },
{ {
@@ -166,7 +166,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Similarly, when using other data types\n",
"相似地,当我们使用其他的数据类型时\n",
"\n", "\n",
" - %s -> string\n", " - %s -> string\n",
" - %d -> Integer\n", " - %d -> Integer\n",
@@ -174,8 +174,8 @@
" - %o -> Octal\n", " - %o -> Octal\n",
" - %x -> Hexadecimal\n", " - %x -> Hexadecimal\n",
" - %e -> exponential\n", " - %e -> exponential\n",
" \n",
"This can be used for conversions inside the print statement itself."
" \n",
"这可以用于print语句本身内部的转换。"
] ]
}, },
{ {
@@ -207,7 +207,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"When referring to multiple variables parenthesis is used."
"当引用多个变量时使用圆括号。"
] ]
}, },
{ {
@@ -231,14 +231,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 1. Other Examples"
"## 1. 其他例子"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The following are other different ways the print statement can be put to use."
"下面是使用print语句的其他不同方式。"
] ]
}, },
{ {
@@ -370,16 +370,16 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# 2. PrecisionWidth and FieldWidth"
"# 2. PrecisionWidthFieldWidth"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Fieldwidth is the width of the entire number and precision is the width towards the right. One can alter these widths based on the requirements.\n",
"Fieldwidth是整个数字的宽度,精度是向右的宽度。你可以根据需要改变这些宽度。\n",
"\n", "\n",
"The default Precision Width is set to 6."
"默认的精度宽度设置为6。"
] ]
}, },
{ {
@@ -406,7 +406,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Notice upto 6 decimal points are returned. To specify the number of decimal points, '%(fieldwidth).(precisionwidth)f' is used."
"注意,最多返回6个小数点。要指定小数点的数目,使用'%(fieldwidth).(precisionwidth)f'。"
] ]
}, },
{ {
@@ -433,7 +433,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If the field width is set more than the necessary than the data right aligns itself to adjust to the specified values."
"如果字段宽度设置超过所需,则数据将自己对齐以调整到指定的值。"
] ]
}, },
{ {
@@ -460,7 +460,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Zero padding is done by adding a 0 at the start of fieldwidth."
"零填充通过在字段宽度的开始处添加一个0来完成。"
] ]
}, },
{ {
@@ -487,7 +487,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"For proper alignment, a space can be left blank in the field width so that when a negative number is used, proper alignment is maintained."
"为了正确对齐,字段宽度中的空格可以留空,以便在使用负数时保持正确的对齐。"
] ]
}, },
{ {
@@ -513,7 +513,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"'+' sign can be returned at the beginning of a positive number by adding a + sign at the beginning of the field width."
"通过在字段宽度的开始处添加一个+号,可以在正数的开始处返回'+'号。"
] ]
}, },
{ {
@@ -539,7 +539,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"As mentioned above, the data right aligns itself when the field width mentioned is larger than the actualy field width. But left alignment can be done by specifying a negative symbol in the field width."
"如上所述,当提到的字段宽度大于实际字段宽度时,数据右对齐。但是可以通过在字段宽度中指定一个负符号来实现左对齐。"
] ]
}, },
{ {


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

@@ -4,30 +4,30 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Data Structures"
"# 数据结构"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In simple terms, It is the the collection or group of data in a particular structure."
"简单地说,它是特定结构中的数据集合或数据组。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 1. Lists"
"## 1. 列表"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Lists are the most commonly used data structure. Think of it as a sequence of data that is enclosed in square brackets and data are separated by a comma. Each of these data can be accessed by calling it's index value.\n",
"列表是最常用的数据结构。可以把它看作用方括号括起来的数据序列,数据之间用逗号分隔。这些数据都可以通过调用其索引值来访问。\n",
"\n", "\n",
"Lists are declared by just equating a variable to '[ ]' or list."
"list的声明只需将变量等同于'[ ]'或list即可。"
] ]
}, },
{ {
@@ -60,7 +60,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"One can directly assign the sequence of data to a list x as shown."
"可以直接将数据序列分配给列表x,如下所示。"
] ]
}, },
{ {
@@ -85,14 +85,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 1.1 Indexing"
"### 1.1 索引"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In python, Indexing starts from 0. Thus now the list x, which has two elements will have apple at 0 index and orange at 1 index."
"在python中,索引从0开始。因此,现在包含两个元素的列表x的apple索引值为0,orange索引值为1。"
] ]
}, },
{ {
@@ -119,7 +119,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Indexing can also be done in reverse order. That is the last element can be accessed first. Here, indexing starts from -1. Thus index value -1 will be orange and index -2 will be apple."
"索引也可以按照相反的顺序进行。这是最后一个可以被首先访问的元素。这里,索引从-1开始。因此,指数-1将是橙色,指数-2将是苹果。"
] ]
}, },
{ {
@@ -146,7 +146,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"As you might have already guessed, x[0] = x[-2], x[1] = x[-1]. This concept can be extended towards lists with more many elements."
"正如你可能猜到的一样,x[0] = x[-2], x[1] = x[-1]。这个概念可以扩展到更多包含元素的列表。"
] ]
}, },
{ {
@@ -162,7 +162,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Here we have declared two lists x and y each containing its own data. Now, these two lists can again be put into another list say z which will have it's data as two lists. This list inside a list is called as nested lists and is how an array would be declared which we will see later."
"在这里我们已经声明过两个列表x和y每一个包含自己的数据。现在,这两个列表可以再一次被放入另一个也具有自己的数据的列表z中。列表中的这个列表被称为嵌套列表,这就是数组的声明方式,我们将在后面看到。"
] ]
}, },
{ {
@@ -207,10 +207,10 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Indexing in nested lists can be quite confusing if you do not understand how indexing works in python. So let us break it down and then arrive at a conclusion.\n",
"如果您不了解在python中索引是如何工作的,那么在嵌套列表中索引可能会非常令人困惑。所以让我们把它分解一下,然后得出一个结论。\n",
"\n", "\n",
"Let us access the data 'apple' in the above nested list.\n",
"First, at index 0 there is a list ['apple','orange'] and at index 1 there is another list ['carrot','potato']. Hence z[0] should give us the first list which contains 'apple'."
"让我们在上述嵌套列表中获得数据'apple'。\n",
"首先在索引为0处,有一个列表['apple','orange'] 而在索引为1处有另外一个列表['carrot','potato'] 。因此z[0] 应该给我们第一个包含'apple'的列表。"
] ]
}, },
{ {
@@ -235,7 +235,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now observe that z1 is not at all a nested list thus to access 'apple', z1 should be indexed at 0."
"现在观察z1并不是一个嵌套列表,因此为了获得'apple',z1的索引应该为0。"
] ]
}, },
{ {
@@ -262,7 +262,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Instead of doing the above, In python, you can access 'apple' by just writing the index values each time side by side."
"在python中,你可以通过每次并排写索引值来访问“apple”,而不是像上面那样做。"
] ]
}, },
{ {
@@ -289,23 +289,23 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If there was a list inside a list inside a list then you can access the innermost value by executing z[ ][ ][ ]."
"如果列表中有一个列表,那么您可以通过执行 z[ ][ ][ ] 来访问最里面的值。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 1.2 Slicing"
"### 1.2 切片"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Indexing was only limited to accessing a single element, Slicing on the other hand is accessing a sequence of data inside the list. In other words \"slicing\" the list.\n",
"索引只限于访问单个元素,而切片则是访问列表内的一系列数据。换句话说,“切片”列表。\n",
"\n", "\n",
"Slicing is done by defining the index values of the first element and the last element from the parent list that is required in the sliced list. It is written as parentlist[ a : b ] where a,b are the index values from the parent list. If a or b is not defined then the index value is considered to be the first value for a if a is not defined and the last value for b when b is not defined."
"切片是通过定义切片列表中需要的父列表中的第一个元素和最后一个元素的索引值来完成的。它被写成parentlist[a: b],其中a,b是父列表的索引值。如果a或b未定义,则认为该索引值是a未定义时的第一个值,以及b未定义时的最后一个值。"
] ]
}, },
{ {
@@ -353,7 +353,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"You can also slice a parent list with a fixed length or step length."
"您还可以使用固定长度或步长对父列表进行切片。"
] ]
}, },
{ {
@@ -380,14 +380,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 1.3 Built in List Functions"
"### 1.3 构造列表函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"To find the length of the list or the number of elements in a list, **len( )** is used."
"为了找到列表的长度或者列表中元素的数量,我们可以使用**len( )**。"
] ]
}, },
{ {
@@ -414,7 +414,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If the list consists of all integer elements then **min( )** and **max( )** gives the minimum and maximum value in the list."
"如果列表包含所有的整数元素,那么 **min( )** 和 **max( )** 给出列表中的最大值和最小值。"
] ]
}, },
{ {
@@ -461,7 +461,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Lists can be concatenated by adding, '+' them. The resultant list will contain all the elements of the lists that were added. The resultant list will not be a nested list."
"列表可以通过添加'+'来连接。生成的列表将包含添加的列表的所有元素。结果列表将不是嵌套列表。"
] ]
}, },
{ {
@@ -488,7 +488,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"There might arise a requirement where you might need to check if a particular element is there in a predefined list. Consider the below list."
"可能会出现这样的需求,您可能需要检查预定义列表中是否存在特定的元素。考虑下面的列表。"
] ]
}, },
{ {
@@ -504,7 +504,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"To check if 'Fire' and 'Rajath' is present in the list names. A conventional approach would be to use a for loop and iterate over the list and use the if condition. But in python you can use 'a in b' concept which would return 'True' if a is present in b and 'False' if not."
"检查“Fire”和“Rajath”是否出现在列表名称中。传统的方法是使用for循环遍历列表并使用if条件。但在python中,你可以使用\" a在b中\"的概念,如果a在b中出现,它会返回\"True\"如果不是,它会返回\"False\""
] ]
}, },
{ {
@@ -591,7 +591,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In a list with elements as string, **max( )** and **min( )** is applicable. **max( )** would return a string element whose ASCII value is the highest and the lowest when **min( )** is used. Note that only the first index of each element is considered each time and if they value is the same then second index considered so on and so forth."
"。在一个有字符串作为元素的列表中,**max( )** 和 **min( )** 是可以应用的。**max( )** 会返回一个ASCII码最高的元素而最低的元素会在使用**min( )** 返回。注意,每次只考虑每个元素的第一个索引,如果它们的值相同,则考虑第二个索引,依此类推。"
] ]
}, },
{ {
@@ -626,7 +626,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Here the first index of each element is considered and thus z has the highest ASCII value thus it is returned and minimum ASCII is a. But what if numbers are declared as strings?"
"这里考虑每个元素的第一个索引,因此z有最高的ASCII值,因此它被返回,最小的ASCII值是a。但是如果数字被声明为字符串呢?"
] ]
}, },
{ {
@@ -661,14 +661,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Even if the numbers are declared in a string the first index of each element is considered and the maximum and minimum values are returned accordingly."
"即使数字是在字符串中声明的,也会考虑每个元素的第一个索引,并相应地返回最大值和最小值。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"But if you want to find the **max( )** string element based on the length of the string then another parameter 'key=len' is declared inside the **max( )** and **min( )** function."
"但是如果你想找到给予字符串长度的 **max( )** 字符串元素,那么我们要在 **max( )** 和 **min( )** 中声明参数'key=len'。"
] ]
}, },
{ {
@@ -694,11 +694,11 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"But even 'Water' has length 5. **max()** or **min()** function returns the first element when there are two or more elements with the same length.\n",
"但是即使'Water'的长度为5。**max()** 或 **min()** 函数返回第一个元素当两个或者多个元素具有相同的长度。\n",
"\n", "\n",
"Any other built in function can be used or lambda function (will be discussed later) in place of len.\n",
"可以使用任何其他内建函数或lambda函数(后面将讨论)来代替len。\n",
"\n", "\n",
"A string can be converted into a list by using the **list()** function."
"通过使用**list()** 函数,一个字符串可以被转化成列表。"
] ]
}, },
{ {
@@ -725,7 +725,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**append( )** is used to add a element at the end of the list."
"**append( )** 被用来在列表的最后添加一个元素。"
] ]
}, },
{ {
@@ -759,7 +759,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**count( )** is used to count the number of a particular element that is present in the list. "
"**count( )** 用于计算列表中出现的特定元素的数量。"
] ]
}, },
{ {
@@ -786,7 +786,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**append( )** function can also be used to add a entire list at the end. Observe that the resultant list becomes a nested list."
"**append( )** 函数也可以被用来在末尾添加一整个列表。观察可以发现最终得到的列表是嵌套列表。"
] ]
}, },
{ {
@@ -820,7 +820,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"But if nested list is not what is desired then **extend( )** function can be used."
"但是如果嵌套列表不是需要的,那么可以使用**extend()** 函数。"
] ]
}, },
{ {
@@ -845,7 +845,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**index( )** is used to find the index value of a particular element. Note that if there are multiple elements of the same value then the first index value of that element is returned."
"**index( )** 被用来找到一个特殊元素的索引值。注意如果有许多个元素具有相同的值那么元素第一个索引值会被返回。"
] ]
}, },
{ {
@@ -893,7 +893,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**insert(x,y)** is used to insert a element y at a specified index value x. **append( )** function made it only possible to insert at the end. "
"**insert(x,y)** 用于在指定的索引值x处插入元素y。**append( )** 函数使得它只能插在最后。"
] ]
}, },
{ {
@@ -922,7 +922,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**insert(x,y)** inserts but does not replace element. If you want to replace the element with another element you simply assign the value to that particular index."
"**insert(x,y)** 插入但不替换元素。如果希望用另一个元素替换该元素,只需将值赋给该特定索引。"
] ]
}, },
{ {
@@ -947,7 +947,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**pop( )** function return the last element in the list. This is similar to the operation of a stack. Hence it wouldn't be wrong to tell that lists can be used as a stack."
"**pop( )** 函数返回列表中的最后一个元素。这类似于堆栈的操作。因此,说列表可以作为堆栈使用是正确的。"
] ]
}, },
{ {
@@ -975,7 +975,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Index value can be specified to pop a ceratin element corresponding to that index value."
"可以指定索引值来弹出与该索引值对应的元素。"
] ]
}, },
{ {
@@ -1019,7 +1019,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**pop( )** is used to remove element based on it's index value which can be assigned to a variable. One can also remove element by specifying the element itself using the **remove( )** function."
"**pop( )** 用于根据可分配给变量的元素的索引值来删除元素。还可以通过使用**remove()** 函数指定元素本身来删除元素。"
] ]
}, },
{ {
@@ -1044,7 +1044,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Alternative to **remove** function but with using index value is **del**"
"可以替代 **remove** 但是使用索引值的函数是 **del**。"
] ]
}, },
{ {
@@ -1071,7 +1071,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The entire elements present in the list can be reversed by using the **reverse()** function."
"可以使用**reverse()** 函数反转列表中出现的所有元素。"
] ]
}, },
{ {
@@ -1096,9 +1096,9 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Note that the nested list [5,4,2,8] is treated as a single element of the parent list lst. Thus the elements inside the nested list is not reversed.\n",
"注意嵌套列表 [5,4,2,8] 被视为父列表lst的单个元素。因此在嵌套列表里的元素是不可以被翻转的。\n",
"\n", "\n",
"Python offers built in operation **sort( )** to arrange the elements in ascending order."
"Python提供了内置函数 **sort( )** 去按升序排列元素。"
] ]
}, },
{ {
@@ -1124,7 +1124,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"For descending order, By default the reverse condition will be False for reverse. Hence changing it to True would arrange the elements in descending order."
"对于降序,因为默认情况下反向条件为False。因此,将其更改为True将按降序排列元素。"
] ]
}, },
{ {
@@ -1149,7 +1149,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Similarly for lists containing string elements, **sort( )** would sort the elements based on it's ASCII value in ascending and by specifying reverse=True in descending."
"相似地对于包含字符串元素的列表, **sort( )** 会根据他们的ASCII值以升序的方式排列而通过确定reverse=True可以让他们以降序的方式排列。"
] ]
}, },
{ {
@@ -1178,7 +1178,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"To sort based on length key=len should be specified as shown."
"如果要根据长度排序我们应该像图示的一样确定key=len。"
] ]
}, },
{ {
@@ -1206,14 +1206,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 1.4 Copying a list"
"### 1.4 复制一个列表"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Most of the new python programmers commit this mistake. Consider the following,"
"大多数新的python程序员都会犯这个错误。考虑以下,"
] ]
}, },
{ {
@@ -1247,7 +1247,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Here, We have declared a list, lista = [2,1,4,3]. This list is copied to listb by assigning it's value and it get's copied as seen. Now we perform some random operations on lista."
"这里,我们声明了一个列表,lista = [2,1,4,3]。通过赋值将该列表复制到listb,并复制该列表。现在我们对lista执行一些随机操作。"
] ]
}, },
{ {
@@ -1292,9 +1292,9 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"listb has also changed though no operation has been performed on it. This is because you have assigned the same memory space of lista to listb. So how do fix this?\n",
"虽然没有对listb执行任何操作,但它也发生了变化。这是因为您将lista的内存空间分配给了listb。那么如何解决这个问题呢?\n",
"\n", "\n",
"If you recall, in slicing we had seen that parentlist[a:b] returns a list from parent list with start index a and end index b and if a and b is not mentioned then by default it considers the first and last element. We use the same concept here. By doing so, we are assigning the data of lista to listb as a variable."
"如果您还记得,在切片中我们已经看到parentlist[a:b]从父列表返回一个起始索引a和结束索引b的列表,如果a和b没有被提及,那么默认情况下它会考虑第一个和最后一个元素。我们在这里使用相同的概念。通过这样做,我们将lista的数据作为变量分配给listb。"
] ]
}, },
{ {
@@ -1366,14 +1366,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2. Tuples"
"## 2. 元组"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Tuples are similar to lists but only big difference is the elements inside a list can be changed but in tuple it cannot be changed. Think of tuples as something which has to be True for a particular something and cannot be True for no other values. For better understanding, Recall **divmod()** function."
"元组与列表相似,但唯一大的区别是列表中的元素可以更改,而元组中的元素不能更改。把元组想象成对特定的东西为True,而对其他任何值都不为True。为了更好地理解,请回忆**divmod()** 函数。"
] ]
}, },
{ {
@@ -1400,14 +1400,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Here the quotient has to be 3 and the remainder has to be 1. These values cannot be changed whatsoever when 10 is divided by 3. Hence divmod returns these values in a tuple."
"这里的商必须是3余数必须是1。当10除以3时,这些值不能改变。因此,divmod以元组的形式返回这些值。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"To define a tuple, A variable is assigned to paranthesis ( ) or tuple( )."
"要定义元组,将一个变量分配给paranthesis()或tuple()。"
] ]
}, },
{ {
@@ -1424,7 +1424,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If you want to directly declare a tuple it can be done by using a comma at the end of the data."
"如果想直接声明元组,可以在数据的末尾使用逗号。"
] ]
}, },
{ {
@@ -1451,7 +1451,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"27 when multiplied by 2 yields 54, But when multiplied with a tuple the data is repeated twice."
"27乘以2得到54,但是乘以一个元组,数据重复两次。"
] ]
}, },
{ {
@@ -1478,7 +1478,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Values can be assigned while declaring a tuple. It takes a list as input and converts it into a tuple or it takes a string and converts it into a tuple."
"在声明元组时可以分配值。它接受一个列表作为输入并将其转换为元组,或者接受一个字符串并将其转换为元组。"
] ]
}, },
{ {
@@ -1508,7 +1508,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"It follows the same indexing and slicing as Lists."
"它遵循与列表相同的索引和切片。"
] ]
}, },
{ {
@@ -1535,7 +1535,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 2.1 Mapping one tuple to another"
"### 2.1 将一个元组映射到另一个元组"
] ]
}, },
{ {
@@ -1586,14 +1586,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 2.2 Built In Tuple functions"
"### 2.2 内置元组函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**count()** function counts the number of specified element that is present in the tuple."
"**count()** 函数计算元组中存在的指定元素的数量。"
] ]
}, },
{ {
@@ -1620,7 +1620,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**index()** function returns the index of the specified element. If the elements are more than one then the index of the first element of that specified element is returned"
"**index()** 函数返回指定元素的索引。如果元素大于1,则返回该指定元素的第一个元素的索引"
] ]
}, },
{ {
@@ -1647,16 +1647,16 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 3. Sets"
"## 3. 集合"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Sets are mainly used to eliminate repeated numbers in a sequence/list. It is also used to perform some standard set operations.\n",
"集合主要用于消除序列/列表中的重复数字。它还用于执行一些标准的集合操作。\n",
"\n", "\n",
"Sets are declared as set() which will initialize a empty set. Also set([sequence]) can be executed to declare a set with elements"
"set被声明为set(),它将初始化一个空集。set([sequence])也可以被执行来声明一个包含元素的集"
] ]
}, },
{ {
@@ -1699,14 +1699,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"elements 2,3 which are repeated twice are seen only once. Thus in a set each element is distinct."
"重复两次的元素2,3只会出现一次。因此在一个集合中,每个元素都是不同的。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 3.1 Built-in Functions"
"### 3.1 内置函数"
] ]
}, },
{ {
@@ -1731,7 +1731,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**union( )** function returns a set which contains all the elements of both the sets without repition."
"**union( )** 函数返回一个集合,该集合包含两个集合的所有元素,但是没有重复。"
] ]
}, },
{ {
@@ -1758,7 +1758,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**add( )** will add a particular element into the set. Note that the index of the newly added element is arbitrary and can be placed anywhere not neccessarily in the end."
"**add()** 将向集合中添加一个特定的元素。注意,新添加的元素的索引是任意的,可以放在末尾不需要的任何位置。"
] ]
}, },
{ {
@@ -1794,7 +1794,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**intersection( )** function outputs a set which contains all the elements that are in both sets."
"**intersection( )** 函数输出一个集合,该集合包含两个集合中的所有元素。"
] ]
}, },
{ {
@@ -1821,7 +1821,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**difference( )** function ouptuts a set which contains elements that are in set1 and not in set2."
"**difference( )** 函数输出一个集合,其中包含在set1中而不在set2中的元素。"
] ]
}, },
{ {
@@ -1848,7 +1848,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**symmetric_difference( )** function ouputs a function which contains elements that are in one of the sets."
"**symmetric_difference( )** 函数输出一个函数,该函数包含一个集合中的元素。"
] ]
}, },
{ {
@@ -1875,7 +1875,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**issubset( ), isdisjoint( ), issuperset( )** is used to check if the set1/set2 is a subset, disjoint or superset of set2/set1 respectively."
"**issubset( ), isdisjoint( ), issuperset( )** 分别用于检查set1/set2是否是set2/set1的子集、不相交或超集。"
] ]
}, },
{ {
@@ -1920,7 +1920,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**pop( )** is used to remove an arbitrary element in the set"
"**pop( )** 是用来移除集合中的任意元素。"
] ]
}, },
{ {
@@ -1937,7 +1937,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**remove( )** function deletes the specified element from the set."
"**remove( )** 函数从集合中删除指定的元素。"
] ]
}, },
{ {
@@ -1954,7 +1954,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**clear( )** is used to clear all the elements and make that set an empty set."
"**clear( )** 用于清除所有元素并将其设置为空集。"
] ]
}, },
{ {


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

@@ -4,14 +4,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 1. Strings"
"## 1. 字符串"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Strings are ordered text based data which are represented by enclosing the same in single/double/triple quotes."
"字符串是基于文本的有序数据,用单/双/三重引号括起来表示。"
] ]
}, },
{ {
@@ -62,7 +62,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"String Indexing and Slicing are similar to Lists which was explained in detail earlier."
"字符串索引和分段类似于前面详细解释过的列表。"
] ]
}, },
{ {
@@ -88,14 +88,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 1.1 Built-in Functions"
"### 1.1 内置函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**find( )** function returns the index value of the given data that is to found in the string. If it is not found it returns **-1**. Remember to not confuse the returned -1 for reverse indexing value."
"**find( )** 函数返回要在字符串中找到的给定数据的索引值。如果没有找到它,它返回 **-1**。记住不要将返回的-1与反向索引值混淆。"
] ]
}, },
{ {
@@ -121,7 +121,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The index value returned is the index of the first element in the input data."
"返回的索引值是输入数据中第一个元素的索引。"
] ]
}, },
{ {
@@ -145,7 +145,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"One can also input **find( )** function between which index values it has to search."
"还可以输入**find()** 函数,在它们之间搜索索引值。"
] ]
}, },
{ {
@@ -171,7 +171,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**capitalize( )** is used to capitalize the first element in the string."
"**capitalize( )** 用于将字符串中的第一个元素大写。"
] ]
}, },
{ {
@@ -196,7 +196,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**center( )** is used to center align the string by specifying the field width."
"**center( )** 用于通过指定字段宽度将字符串居中对齐。"
] ]
}, },
{ {
@@ -250,7 +250,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**zfill( )** is used for zero padding by specifying the field width."
"**zfill( )** 通过指定字段宽度来填充零。"
] ]
}, },
{ {
@@ -277,7 +277,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**expandtabs( )** allows you to change the spacing of the tab character. '\\t' which is by default set to 8 spaces."
"**expandtabs( )** 允许您更改制表符的间距。'\\t'默认设置为8个空格。"
] ]
}, },
{ {
@@ -308,7 +308,7 @@
"collapsed": true "collapsed": true
}, },
"source": [ "source": [
"**index( )** works the same way as **find( )** function the only difference is find returns '-1' when the input element is not found in the string but **index( )** function throws a ValueError"
"**index( )** 和 **find( )** 函数的工作方式相同,唯一的区别在于 **find( )** 返回'-1',当输入元素在字符串中没有找到,但是**index( )** 函数会抛出一个ValueError。"
] ]
}, },
{ {
@@ -346,7 +346,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**endswith( )** function is used to check if the given string ends with the particular char which is given as input."
"**endswith( )** 函数用于检查给定字符串是否以作为输入的特定字符结尾。"
] ]
}, },
{ {
@@ -370,7 +370,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The start and stop index values can also be specified."
"还可以指定开始和停止索引值。"
] ]
}, },
{ {
@@ -396,7 +396,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**count( )** function counts the number of char in the given string. The start and the stop index can also be specified or left blank. (These are Implicit arguments which will be dealt in functions)"
"**count( )** 函数计算给定字符串中的字符数。也可以指定开始和停止索引或将其留空。(这些是隐式参数,将在函数中处理)"
] ]
}, },
{ {
@@ -422,7 +422,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**join( )** function is used add a char in between the elements of the input string."
"**join( )** 函数在输入字符串的元素之间添加一个字符。"
] ]
}, },
{ {
@@ -469,14 +469,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"'*_-' is the input string and char 'a' is added in between each element"
"'*_-' 是输入字符串而字符'a'被添加在每一个元素之间。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**join( )** function can also be used to convert a list into a string."
"**join( )** 函数也可以被用来将列表转化为字符串。"
] ]
}, },
{ {
@@ -504,7 +504,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Before converting it into a string **join( )** function can be used to insert any char in between the list elements."
"在将它转化成字符串之前,**join( )** 函数可以被用来在列表元素中插入任意的字符。"
] ]
}, },
{ {
@@ -529,7 +529,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**split( )** function is used to convert a string back to a list. Think of it as the opposite of the **join()** function."
"**split( )** 函数被用来将一个字符串转化为列表。把它想成与**join()** 相反地函数。"
] ]
}, },
{ {
@@ -554,7 +554,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In **split( )** function one can also specify the number of times you want to split the string or the number of elements the new returned list should conatin. The number of elements is always one more than the specified number this is because it is split the number of times specified."
"在 **split( )** 函数中,还可以指定分割字符串的次数,或者新返回列表应该包含的元素数量。元素的数量总是比指定的数量多1,这是因为它被分割了指定的次数。"
] ]
}, },
{ {
@@ -581,7 +581,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**lower( )** converts any capital letter to small letter."
"**lower( )** 将任何大写字母转换为小写字母。"
] ]
}, },
{ {
@@ -607,7 +607,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**upper( )** converts any small letter to capital letter."
"**upper( )** 将任何小写字母转换为大写字母。"
] ]
}, },
{ {
@@ -634,7 +634,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**replace( )** function replaces the element with another element."
"**replace( )** 函数将该元素替换为另一个元素。"
] ]
}, },
{ {
@@ -661,7 +661,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**strip( )** function is used to delete elements from the right end and the left end which is not required."
"**strip( )** 函数用于从右端和左端删除不需要的元素。"
] ]
}, },
{ {
@@ -677,7 +677,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If no char is specified then it will delete all the spaces that is present in the right and left hand side of the data."
"如果没有指定字符,那么它将删除数据左边和右边的所有空格。"
] ]
}, },
{ {
@@ -704,7 +704,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**strip( )** function, when a char is specified then it deletes that char if it is present in the two ends of the specified string."
"**strip( )** 函数,当指定字符时,如果该字符出现在指定字符串的两端,则删除该字符。"
] ]
}, },
{ {
@@ -740,7 +740,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The asterisk had to be deleted but is not. This is because there is a space in both the right and left hand side. So in strip function. The characters need to be inputted in the specific order in which they are present."
"必须删除星号,但没有。这是因为在左边和右边都有一个空格。在strip函数中。字符需要按照它们出现的特定顺序输入。"
] ]
}, },
{ {
@@ -766,7 +766,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**lstrip( )** and **rstrip( )** function have the same functionality as strip function but the only difference is **lstrip( )** deletes only towards the left side and **rstrip( )** towards the right."
"**lstrip( )** 和 **rstrip( )** 函数具有与strip函数相同的功能,但唯一的区别是**lstrip()** 只删除左边的内容,而**rstrip()** 只删除右边的内容。"
] ]
}, },
{ {
@@ -792,21 +792,21 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2. Dictionaries"
"## 2. 词典"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Dictionaries are more used like a database because here you can index a particular sequence with your user defined string."
"字典更像数据库,因为在这里您可以用用户定义的字符串索引特定的序列。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"To define a dictionary, equate a variable to { } or dict()"
"为了定义一个词典,让一个变量和{ }或dict()相等。"
] ]
}, },
{ {
@@ -832,7 +832,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Dictionary works somewhat like a list but with an added capability of assigning it's own index style."
"词典的工作方式有点像列表,但增加了分配自己索引样式的功能。"
] ]
}, },
{ {
@@ -876,7 +876,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"That is how a dictionary looks like. Now you are able to access '1' by the index value set at 'One'"
"这就是字典的样子。现在你可以通过设为'One'的索引值来访问'1'了"
] ]
}, },
{ {
@@ -900,7 +900,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Two lists which are related can be merged to form a dictionary."
"两个相关的列表可以合并成一个字典。"
] ]
}, },
{ {
@@ -917,7 +917,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**zip( )** function is used to combine two lists"
"**zip( )** 函数用来结合两个列表。"
] ]
}, },
{ {
@@ -942,9 +942,9 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The two lists are combined to form a single list and each elements are clubbed with their respective elements from the other list inside a tuple. Tuples because that is what is assigned and the value should not change.\n",
"这两个列表组合成一个列表,每个元素都与元组中来自另一个列表的各自元素相连。元组,因为它是被分配的,而且值不应该改变。\n",
"\n", "\n",
"Further, To convert the above into a dictionary. **dict( )** function is used."
"进一步地,为了将上面的内容转化为词典。我们可以使用 **dict( )** 函数。"
] ]
}, },
{ {
@@ -971,14 +971,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 2.1 Built-in Functions"
"### 2.1 内置函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**clear( )** function is used to erase the entire database that was created."
"**clear( )** 函数被用于擦除所创建的整个数据库。"
] ]
}, },
{ {
@@ -1003,7 +1003,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Dictionary can also be built using loops."
"字典也可以使用循环来构建。"
] ]
}, },
{ {
@@ -1047,7 +1047,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**values( )** function returns a list with all the assigned values in the dictionary."
"**values( )** 函数返回了一个包含字典中所有赋值的列表"
] ]
}, },
{ {
@@ -1074,7 +1074,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**keys( )** function returns all the index or the keys to which contains the values that it was assigned to."
"**keys( )** 函数返回包含赋值的所有索引或键。"
] ]
}, },
{ {
@@ -1101,7 +1101,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**items( )** is returns a list containing both the list but each element in the dictionary is inside a tuple. This is same as the result that was obtained when zip function was used."
"**items()** 返回一个列表同时也包含该列表,但是字典中的每个元素都在一个元组中。这与使用zip函数得到的结果相同。"
] ]
}, },
{ {
@@ -1132,7 +1132,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**pop( )** function is used to get the remove that particular element and this removed element can be assigned to a new variable. But remember only the value is stored and not the key. Because the is just a index value."
"**pop()** 函数用于删除特定的元素,并且这个删除的元素可以被分配给一个新的变量。但是请记住,只存储值而不存储键。因为它只是一个索引值。"
] ]
}, },
{ {


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

@@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Control Flow Statements"
"# 控制流语句"
] ]
}, },
{ {
@@ -137,7 +137,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"if statement inside a if statement or if-elif or if-else are called as nested if statements."
"在if语句里的if语句,if-elif或if-else都被称为嵌套if语句。"
] ]
}, },
{ {
@@ -173,7 +173,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 4. Loops"
"## 4. 循环"
] ]
}, },
{ {
@@ -240,7 +240,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In the above example, i iterates over the 0,1,2,3,4. Every time it takes each value and executes the algorithm inside the loop. It is also possible to iterate over a nested list illustrated below."
"在上面的例子中,我遍历了0,1,2,3,4。每次它取每个值并在循环内执行算法。还可以遍历如下所示的嵌套列表。"
] ]
}, },
{ {
@@ -268,7 +268,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"A use case of a nested for loop in this case would be,"
"嵌套的for循环的一个用例是,"
] ]
}, },
{ {
@@ -370,7 +370,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"As the name says. It is used to break out of a loop when a condition becomes true when executing the loop."
"顾名思义。它用于在执行循环时,当条件为真时中断循环。"
] ]
}, },
{ {
@@ -411,7 +411,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"This continues the rest of the loop. Sometimes when a condition is satisfied there are chances of the loop getting terminated. This can be avoided using continue statement. "
"这将继续循环的其余部分。有时,当满足条件时,循环有可能终止。这可以使用continue语句避免。"
] ]
}, },
{ {
@@ -456,7 +456,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Python makes it simple to generate a required list with a single line of code using list comprehensions. For example If i need to generate multiples of say 27 I write the code using for loop as,"
"Python使用列表理解式,用一行代码就可以很容易地生成所需的列表。例如,如果我需要生成27的倍数,我用For loop写代码,"
] ]
}, },
{ {
@@ -484,7 +484,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Since you are generating another list altogether and that is what is required, List comprehensions is a more efficient way to solve this problem."
"由于你需要生成另一个列表,所以列表理解是解决这个问题的更有效的方法。"
] ]
}, },
{ {
@@ -511,14 +511,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"That's it!. Only remember to enclose it in square brackets"
"就是这样!只记得用方括号括起来。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Understanding the code, The first bit of the code is always the algorithm and then leave a space and then write the necessary loop. But you might be wondering can nested loops be extended to list comprehensions? Yes you can."
"理解代码,代码的第一个位总是算法,然后留下一个空格,然后写必要的循环。但是你可能想知道嵌套循环可以扩展到列表理解吗?是的,你可以。"
] ]
}, },
{ {
@@ -596,7 +596,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Let me add one more loop to make you understand better, "
"让我再加一个循环,让你更好地理解,"
] ]
}, },
{ {


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

@@ -4,21 +4,21 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Functions"
"# 函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Most of the times, In a algorithm the statements keep repeating and it will be a tedious job to execute the same statements again and again and will consume a lot of memory and is not efficient. Enter Functions."
"在大部分时候,在一个算法中,语句是不断重复的,一次又一次地执行相同的语句是一项乏味的工作,而且会消耗大量的内存,效率不高。这个时候我们就需要函数。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"This is the basic syntax of a function"
"这是一个函数的基本语法"
] ]
}, },
{ {
@@ -41,7 +41,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Read the above syntax as, A function by name \"funcname\" is defined, which accepts arguements \"arg1,arg2,....argN\". The function is documented and it is '''Document String'''. The function after executing the statements returns a \"value\"."
"将上面的语法理解为,定义了一个名为“funcname”的函数,它接受“arg1,arg2,…argN”的论点。函数被记录为“文档字符串”。函数在执行语句后返回一个“值”。"
] ]
}, },
{ {
@@ -67,9 +67,9 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Instead of writing the above two statements every single time it can be replaced by defining a function which would do the job in just one line. \n",
"不需要每次都写上面的两个语句,可以通过定义一个函数来替换它,这个函数只需一行就能完成任务。\n",
"\n", "\n",
"Defining a function firstfunc()."
"定义一个函数 firstfunc()."
] ]
}, },
{ {
@@ -109,7 +109,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**firstfunc()** every time just prints the message to a single person. We can make our function **firstfunc()** to accept arguements which will store the name and then prints respective to that accepted name. To do so, add a argument within the function as shown."
"**firstfunc()** 每一次只打印一个人的消息。我们可以让我们的函数 **firstfunc()** 接受参数,该参数将存储名称然后打印相应地接受名词。为了这样做我们需要像所示的那样在函数内添加一个参数。"
] ]
}, },
{ {
@@ -144,7 +144,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The name \"Guido\" is actually stored in name1. So we pass this variable to the function **firstfunc()** as the variable username because that is the variable that is defined for this function. i.e name1 is passed as username."
"名称“Willam”实际上存储在name1中。我们将这个变量传递给函数**firstfunc()** 作为变量username,因为它是为这个函数定义的变量。即name1作为用户名传递。"
] ]
}, },
{ {
@@ -169,7 +169,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Let us simplify this even further by defining another function **secondfunc()** which accepts the name and stores it inside a variable and then calls the **firstfunc()** from inside the function itself."
"让我们通过定义另一个函数**secondfunc()** 来进一步简化它,该函数接受名称并将其存储在一个变量中,然后从函数本身内部调用**firstfunc()**。"
] ]
}, },
{ {
@@ -209,14 +209,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 1. Return Statement"
"## 1. 返回语句"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"When the function results in some value and that value has to be stored in a variable or needs to be sent back or returned for further operation to the main algorithm, return statement is used."
"当函数产生某个值,并且该值必须存储在一个变量中,或者需要返回或返回给主算法进行进一步操作时,使用return语句。"
] ]
}, },
{ {
@@ -234,7 +234,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The above defined **times( )** function accepts two arguements and return the variable z which contains the result of the product of the two arguements"
"上面定义的**times()** 函数接受两个参数并返回变量z,该变量包含两个参数的乘积结果。"
] ]
}, },
{ {
@@ -259,14 +259,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The z value is stored in variable c and can be used for further operations."
"z值存储在变量c中,可以用于进一步的操作。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Instead of declaring another variable the entire statement itself can be used in the return statement as shown."
"可以在return语句中使用整个语句本身,而不是声明另一个变量,如下所示。"
] ]
}, },
{ {
@@ -302,7 +302,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Since the **times( )** is now defined, we can document it as shown above. This document is returned whenever **times( )** function is called under **help( )** function."
"由于现在定义了**times()**,我们可以如上所示记录它。在**help()** 函数下调用**times()** 函数时返回该文档。"
] ]
}, },
{ {
@@ -339,7 +339,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Multiple variable can also be returned, But keep in mind the order."
"也可以返回多个变量,但请记住顺序。"
] ]
}, },
{ {
@@ -369,7 +369,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If the function is just called without any variable for it to be assigned to, the result is returned inside a tuple. But if the variables are mentioned then the result is assigned to the variable in a particular order which is declared in the return statement."
"如果调用函数时没有为其分配任何变量,则结果将在一个元组中返回。但是如果变量被提到了,那么结果会以特定的顺序分配给变量,这个顺序在return语句中声明。"
] ]
}, },
{ {
@@ -415,14 +415,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 2. Implicit arguments"
"## 2. 隐式参数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"When an argument of a function is common in majority of the cases or it is \"implicit\" this concept is used."
"当一个函数的参数在大多数情况下是常见的或者它是“隐式的”时,使用这个概念。"
] ]
}, },
{ {
@@ -439,14 +439,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**implicitadd( )** is a function accepts two arguments but most of the times the first argument needs to be added just by 3. Hence the second argument is assigned the value 3. Here the second argument is implicit."
"**implicitadd( )** 是一个函数接受两个参数,但大多数时候第一个参数只需要加3。因此,第二个参数被赋值为3。这里第二个参数是隐式的。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now if the second argument is not defined when calling the **implicitadd( )** function then it considered as 3."
"现在,如果在调用**implicitadd()** 函数时没有定义第二个参数,则将其视为3。"
] ]
}, },
{ {
@@ -473,7 +473,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"But if the second argument is specified then this value overrides the implicit value assigned to the argument "
"但如果指定了第二个参数,则此值将覆盖分配给该参数的隐式值"
] ]
}, },
{ {
@@ -520,14 +520,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 3. Any number of arguments"
"## 3. 任意数量的参数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If the number of arguments that is to be accepted by a function is not known then a asterisk symbol is used before the argument."
"如果函数要接受的参数数量未知,则在参数前使用星号。"
] ]
}, },
{ {
@@ -549,7 +549,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The above function accepts any number of arguments, defines a list and appends all the arguments into that list and return the sum of all the arguments."
"上面的函数接受任意数量的参数,定义一个列表,并将所有参数附加到该列表中,并返回所有参数的总和。"
] ]
}, },
{ {
@@ -645,14 +645,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 4. Global and Local Variables"
"## 4. 全局和局部变量"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Whatever variable is declared inside a function is local variable and outside the function in global variable."
"在函数内部声明的变量是局部变量,在函数外部声明的是全局变量。"
] ]
}, },
{ {
@@ -668,7 +668,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In the below function we are appending a element to the declared list inside the function. eg2 variable declared inside the function is a local variable."
"在下面的函数中,我们将在函数内部声明的列表中追加一个元素。函数内部声明的eg2变量是一个局部变量。"
] ]
}, },
{ {
@@ -727,14 +727,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 5. Lambda Functions"
"## 5. Lambda 函数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"These are small functions which are not defined with any name and carry a single expression whose result is returned. Lambda functions comes very handy when operating with lists. These function are defined by the keyword **lambda** followed by the variables, a colon and the respective expression."
"这些小函数没有使用任何名称定义,只携带一个表达式,返回其结果。Lambda函数在操作列表时非常方便。这些函数由关键字**lambda**定义,后面跟着变量、冒号和相应的表达式。"
] ]
}, },
{ {
@@ -841,7 +841,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**map( )** function basically executes the function that is defined to each of the list's element separately."
"**map( )** 函数主要执行分别为列表的每个元素定义的函数。"
] ]
}, },
{ {
@@ -893,7 +893,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"You can also add two lists."
"你也可以添加两个列表。"
] ]
}, },
{ {
@@ -927,7 +927,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Not only lambda function but also other built in functions can also be used."
"不仅可以使用lambda函数,还可以使用其他内建函数。"
] ]
}, },
{ {
@@ -959,7 +959,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**filter( )** function is used to filter out the values in a list. Note that **filter()** function returns the result in a new list."
"**filter( )** 函数用于过滤列表中的值。 注意 **filter()** 函数返回一个新列表中的结果。"
] ]
}, },
{ {
@@ -975,7 +975,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"To get the elements which are less than 5,"
"为了得到小于5的元素。"
] ]
}, },
{ {
@@ -1000,7 +1000,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Notice what happens when **map()** is used."
"注意当使用**map()** 时会发生什么"
] ]
}, },
{ {
@@ -1027,7 +1027,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"We can conclude that, whatever is returned true in **map( )** function that particular element is returned when **filter( )** function is used."
"我们可以得出这样的结论,在**map()** 函数中返回的值为真,在使用**filter()** 函数时将返回特定的元素。"
] ]
}, },
{ {


+ 96
- 65
0_python/7_Class.ipynb View File

@@ -4,21 +4,21 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Classes"
"# 1. 类"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Variables, Lists, Dictionaries etc in python is a object. Without getting into the theory part of Object Oriented Programming, explanation of the concepts will be done along this tutorial."
"Python中的变量、列表、字典等都是对象。不涉及面向对象编程的理论部分,在本教程中对概念进行解释。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"A class is declared as follows"
"类声明如下"
] ]
}, },
{ {
@@ -32,7 +32,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -44,19 +44,19 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**pass** in python means do nothing. "
"**pass** 在python中意味着什么都不做。 "
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Above, a class object named \"FirstClass\" is declared now consider a \"egclass\" which has all the characteristics of \"FirstClass\". So all you have to do is, equate the \"egclass\" to \"FirstClass\". In python jargon this is called as creating an instance. \"egclass\" is the instance of \"FirstClass\""
"上面声明了一个名为“FirstClass”的类对象,现在考虑一个具有“FirstClass”所有特征的“egclass”。所以你所要做的就是,将“egclass”等同于“FirstClass”。在python术语中,这称为创建实例。“egclass”是“FirstClass”的实例"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
@@ -65,7 +65,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6,
"execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -74,7 +74,7 @@
"__main__.FirstClass" "__main__.FirstClass"
] ]
}, },
"execution_count": 6,
"execution_count": 3,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -85,7 +85,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
@@ -94,7 +94,7 @@
"type" "type"
] ]
}, },
"execution_count": 7,
"execution_count": 4,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@@ -107,23 +107,23 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now let us add some \"functionality\" to the class. So that our \"FirstClass\" is defined in a better way. A function inside a class is called as a \"Method\" of that class"
"现在让我们向类中添加一些“功能”。这样我们的FirstClass就有了更好的定义。类内的函数被称为该类的“方法”"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Most of the classes will have a function named \"\\_\\_init\\_\\_\". These are called as magic methods. In this method you basically initialize the variables of that class or any other initial algorithms which is applicable to all methods is specified in this method. A variable inside a class is called an attribute."
"大多数类都有一个名为“\\_\\_init\\_\\_”的函数。这些被称为魔术方法。在这个方法中,你基本上初始化了这个类的变量,或者任何适用于这个方法中指定的所有方法的初始化算法。类中的变量称为属性。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"These helps simplify the process of initializing a instance. For example,\n",
"这有助于简化实例的初始化过程。例如,\n",
"\n", "\n",
"Without the use of magic method or \\_\\_init\\_\\_ which is otherwise called as constructors. One had to define a **init( )** method and call the **init( )** function."
"在不使用魔法方法或被成为构造函数的\\_\\_init\\_\\_ 的情况下,我们必须定义一个**init()** 方法并调用**init()** 函数。"
] ]
}, },
{ {
@@ -152,16 +152,16 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"But when the constructor is defined the \\_\\_init\\_\\_ is called thus intializing the instance created. "
"但是当构造函数被定义后,\\_\\_init\\_\\_被调用,这样初始化实例被创建。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"We will make our \"FirstClass\" to accept two variables name and symbol.\n",
"我们构造我们的\"FirstClass\"去接受两个变量名称和符号。\n",
"\n", "\n",
"I will be explaining about the \"self\" in a while."
"我将会在稍后解释\"self\"。"
] ]
}, },
{ {
@@ -181,7 +181,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now that we have defined a function and added the \\_\\_init\\_\\_ method. We can create a instance of FirstClass which now accepts two arguments. "
"现在我们已经定义了一个函数而且添加了\\_\\_init\\_\\_方法。我们可以创建一个名为FirstClass的实例,该实例现在接受两个参数。"
] ]
}, },
{ {
@@ -219,7 +219,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**dir( )** function comes very handy in looking into what the class contains and what all method it offers"
"**dir( )** 函数在查看类包含什么以及它提供了什么方法时非常方便。"
] ]
}, },
{ {
@@ -292,7 +292,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"**dir( )** of an instance also shows it's defined attributes."
"实例的**dir()** 也显示了它定义的属性。"
] ]
}, },
{ {
@@ -345,7 +345,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Changing the FirstClass function a bit,"
"稍微改变一下FirstClass函数,"
] ]
}, },
{ {
@@ -364,7 +364,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Changing self.name and self.symbol to self.n and self.s respectively will yield,"
"将self.name和self.symbol转化成self.n和self.s会得到:"
] ]
}, },
{ {
@@ -403,7 +403,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"AttributeError, Remember variables are nothing but attributes inside a class? So this means we have not given the correct attribute for the instance."
"AttributeError, 还记得变量就是类中的属性吗?因此,这意味着我们没有为实例提供正确的属性。"
] ]
}, },
{ {
@@ -475,13 +475,13 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"So now we have solved the error. Now let us compare the two examples that we saw.\n",
"现在我们解决了这个错误。现在让我们比较一下我们看到的两个例子。\n",
"\n", "\n",
"When I declared self.name and self.symbol, there was no attribute error for eg1.name and eg1.symbol and when I declared self.n and self.s, there was no attribute error for eg1.n and eg1.s\n",
"当我声明self.name和self.symbol时,使用eg1.name和eg1.symbol没有属性错误。当我声明self.n和self.s时,使用eg1.n和eg1.s没有属性错误。\n",
"\n", "\n",
"From the above we can conclude that self is nothing but the instance itself.\n",
"从以上我们可以得出self就是实例本身。\n",
"\n", "\n",
"Remember, self is not predefined it is userdefined. You can make use of anything you are comfortable with. But it has become a common practice to use self."
"记住,self不是预定义的,它是用户定义的。你可以利用任何你觉得舒服的东西。但是使用self已经成为一种常见的做法。"
] ]
}, },
{ {
@@ -531,7 +531,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Since eg1 and eg2 are instances of FirstClass it need not necessarily be limited to FirstClass itself. It might extend itself by declaring other attributes without having the attribute to be declared inside the FirstClass."
"因为eg1和eg2是FirstClass的实例,所以它不需要被限制在FirstClass本身。它可以通过声明其他属性来扩展自己,而不需要在FirstClass中声明属性。"
] ]
}, },
{ {
@@ -597,11 +597,11 @@
"collapsed": true "collapsed": true
}, },
"source": [ "source": [
"Just like global and local variables as we saw earlier, even classes have it's own types of variables.\n",
"就像我们前面看到的全局变量和局部变量一样,即使类也有自己的变量类型。\n",
"\n", "\n",
"Class Attribute : attributes defined outside the method and is applicable to all the instances.\n",
"类属性:在方法外部定义的属性,适用于所有实例。\n",
"\n", "\n",
"Instance Attribute : attributes defined inside a method and is applicable to only that method and is unique to each instance."
"实例属性:在方法内部定义的属性,只适用于该方法,并且对每个实例都是唯一的。"
] ]
}, },
{ {
@@ -621,7 +621,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Here test is a class attribute and name is a instance attribute."
"这里test是一个类属性,而name是一个实例属性。"
] ]
}, },
{ {
@@ -665,7 +665,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Let us add some more methods to FirstClass."
"让我们添加更多的方法到FirstClass。"
] ]
}, },
{ {
@@ -738,23 +738,24 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The above can also be written as,"
"以上也可以写成:"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 28,
"execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": {
"text/plain": [
"10"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
"ename": "AttributeError",
"evalue": "type object 'FirstClass' has no attribute 'multiply'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-448ee6ad2a26>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mFirstClass\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmultiply\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meg4\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m: type object 'FirstClass' has no attribute 'multiply'"
]
} }
], ],
"source": [ "source": [
@@ -765,21 +766,21 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 1. Inheritance"
"## 2. 继承"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"There might be cases where a new class would have all the previous characteristics of an already defined class. So the new class can \"inherit\" the previous class and add it's own methods to it. This is called as inheritance."
"在某些情况下,新类可能具有已定义类以前的所有特征。因此,新类可以“继承”前一个类,并向其添加自己的方法。这称为继承。"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Consider class SoftwareEngineer which has a method salary."
"考虑类SoftwareEngineer具有薪水的方法。"
] ]
}, },
{ {
@@ -872,7 +873,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now consider another class Artist which tells us about the amount of money an artist earns and his artform."
"现在考虑另一个Artist类,告诉我们艺术家挣的钱的数量和他的艺术形式。"
] ]
}, },
{ {
@@ -971,14 +972,26 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"money method and salary method are the same. So we can generalize the method to salary and inherit the SoftwareEngineer class to Artist class. Now the artist class becomes,"
"money 方法和salary 方法是一样的。因此,我们可以将该方法推广到工资类,并将软件工程师类继承到美术师类。现在艺术类变成了,"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 46,
"execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'SoftwareEngineer' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-6-9b78404b36d6>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mclass\u001b[0m \u001b[0mArtist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mSoftwareEngineer\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[0m\u001b[1;32m 2\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0martform\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mjob\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[1;32m 3\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjob\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mjob\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\"is a\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjob\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mNameError\u001b[0m: name 'SoftwareEngineer' is not defined"
]
}
],
"source": [ "source": [
"class Artist(SoftwareEngineer):\n", "class Artist(SoftwareEngineer):\n",
" def artform(self, job):\n", " def artform(self, job):\n",
@@ -988,9 +1001,21 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 47,
"execution_count": 7,
"metadata": {}, "metadata": {},
"outputs": [],
"outputs": [
{
"ename": "NameError",
"evalue": "name 'Artist' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-7-1c7e054a8f0c>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mArtist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Nishanth'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m21\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'Artist' is not defined"
]
}
],
"source": [ "source": [
"c = Artist('Nishanth',21)" "c = Artist('Nishanth',21)"
] ]
@@ -1064,7 +1089,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Suppose say while inheriting a particular method is not suitable for the new class. One can override this method by defining again that method with the same name inside the new class."
"假设在继承一个特定方法的时候,该方法不适合新类。可以通过在新类中用相同的名称再次定义该方法来重写该方法。"
] ]
}, },
{ {
@@ -1116,7 +1141,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If not sure how many times methods will be called it will become difficult to declare so many variables to carry each result hence it is better to declare a list and append the result."
"如果不确定方法将被调用多少次,那么就很难声明那么多变量来携带每个结果,因此最好声明一个列表并附加结果。"
] ]
}, },
{ {
@@ -1167,7 +1192,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Since xc.data is a list direct list operations can also be performed."
"因为xc.data是一个列表,直接的列表操作也是可以进行的。"
] ]
}, },
{ {
@@ -1210,7 +1235,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If the number of input arguments varies from instance to instance asterisk can be used as shown."
"如果输入参数的数量因实例而异,则可以使用星号。"
] ]
}, },
{ {
@@ -1257,31 +1282,37 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Where to go from here?"
"# 3. 接下来应该怎么做"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Practice alone can help you get the hang of python. Give your self problem statements and solve them. You can also sign up to any competitive coding platform for problem statements. The more you code the more you discover and the more you start appreciating the language.\n",
"\n",
"单独练习可以帮助你掌握python的窍门。给自己一个问题陈述并解决它们。您还可以在任何竞争的编码平台上提交问题求解。你编写的代码越多,你发现的越多,你就越开始欣赏这门语言。\n",
"\n", "\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",
"现在已经向您介绍了python,您可以尝试您感兴趣的领域中的不同python库。我强烈建议您查看这个Python框架、库和软件列表http://awesome-python.com\n",
"\n", "\n",
"\n", "\n",
"The official python documentation : https://docs.python.org/3/\n",
"python官方文档: https://docs.python.org/3/\n",
"\n", "\n",
"Pyton tutorials:\n",
"Pyton 教程:\n",
"* [Python tutorial (廖雪峰)](https://www.liaoxuefeng.com/wiki/1016959663602400)\n", "* [Python tutorial (廖雪峰)](https://www.liaoxuefeng.com/wiki/1016959663602400)\n",
"* [Python基础教程](https://www.runoob.com/python/python-tutorial.html)\n", "* [Python基础教程](https://www.runoob.com/python/python-tutorial.html)\n",
"* [Python官方教程(中文版)](https://docs.python.org/zh-cn/3/tutorial/index.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",
"你也可以参考一些Python的练习程序,是由 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"
"享受解决问题陈述,因为生命短暂,你需要python!"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {


+ 3
- 3
0_python/7_Class_EN.ipynb View File

@@ -4,7 +4,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Classes"
"# 1. Classes"
] ]
}, },
{ {
@@ -765,7 +765,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 1. Inheritance"
"## 2. Inheritance"
] ]
}, },
{ {
@@ -1257,7 +1257,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# Where to go from here?"
"# 3. Where to go from here?"
] ]
}, },
{ {


+ 1
- 1
1_numpy_matplotlib_scipy_sympy/1-numpy_tutorial.ipynb View File

@@ -4882,7 +4882,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.6.8"
} }
}, },
"nbformat": 4, "nbformat": 4,


+ 11
- 4
1_numpy_matplotlib_scipy_sympy/2-matplotlib_simple_tutorial.ipynb View File

@@ -157,7 +157,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 处理多个图形和轴\n",
"### 1.1 处理多个图形和轴\n",
"\n", "\n",
"MATLAB和pyplot都有当前图和当前轴的概念。所有绘图命令都适用于当前轴。函数gca()返回当前轴(matplotlib.axes)。而gcf()返回当前的图(matplotlib.figure)。图实例)。通常,您不必担心这个,因为它都是在后台处理的。下面是创建两个次要情节的脚本。" "MATLAB和pyplot都有当前图和当前轴的概念。所有绘图命令都适用于当前轴。函数gca()返回当前轴(matplotlib.axes)。而gcf()返回当前的图(matplotlib.figure)。图实例)。通常,您不必担心这个,因为它都是在后台处理的。下面是创建两个次要情节的脚本。"
] ]
@@ -239,7 +239,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 应用伪彩色方案进行图像绘图"
"### 2.1 应用伪彩色方案进行图像绘图"
] ]
}, },
{ {
@@ -314,7 +314,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 检查特定的数据范围"
"### 2.2 检查特定的数据范围"
] ]
}, },
{ {
@@ -434,13 +434,20 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## References\n",
"## 3. References\n",
"\n", "\n",
"\n", "\n",
"* [Pyplot tutorial](https://matplotlib.org/users/pyplot_tutorial.html)\n", "* [Pyplot tutorial](https://matplotlib.org/users/pyplot_tutorial.html)\n",
"* [Image tutorial](https://matplotlib.org/users/image_tutorial.html)\n", "* [Image tutorial](https://matplotlib.org/users/image_tutorial.html)\n",
"* [手把手教你用Python做数据可视化](https://mp.weixin.qq.com/s/3Gwdjw8trwTR5uyr4G7EOg)" "* [手把手教你用Python做数据可视化](https://mp.weixin.qq.com/s/3Gwdjw8trwTR5uyr4G7EOg)"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {


+ 29
- 29
1_numpy_matplotlib_scipy_sympy/5-sympy_tutorial.ipynb View File

@@ -32,7 +32,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 简介"
"## 1. 简介"
] ]
}, },
{ {
@@ -85,7 +85,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 符号变量"
"## 2. 符号变量"
] ]
}, },
{ {
@@ -231,7 +231,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 复数"
"### 2.1 复数"
] ]
}, },
{ {
@@ -318,7 +318,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 有理数"
"### 2.2 有理数"
] ]
}, },
{ {
@@ -418,7 +418,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 数值评估"
"## 3 数值评估"
] ]
}, },
{ {
@@ -709,7 +709,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 代数操作"
"## 4. 代数操作"
] ]
}, },
{ {
@@ -723,7 +723,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 展开和乘积"
"### 4.1 展开和乘积"
] ]
}, },
{ {
@@ -879,7 +879,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 化简"
"### 4.2 化简"
] ]
}, },
{ {
@@ -971,7 +971,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### apart 和 together"
"### 4.3 apart 和 together"
] ]
}, },
{ {
@@ -1135,7 +1135,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 微积分"
"## 5 微积分"
] ]
}, },
{ {
@@ -1149,7 +1149,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 微分"
"### 5.1 微分"
] ]
}, },
{ {
@@ -1326,7 +1326,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 积分"
"## 6. 积分"
] ]
}, },
{ {
@@ -1462,7 +1462,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### 加数和乘积"
"### 6.1 加数和乘积"
] ]
}, },
{ {
@@ -1601,7 +1601,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 极限"
"## 7. 极限"
] ]
}, },
{ {
@@ -1796,7 +1796,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## 序列"
"## 8. 序列"
] ]
}, },
{ {
@@ -1915,7 +1915,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"The series expansion includes the order of the approximation, which is very useful for keeping track of the order of validity when we do calculations with series expansions of different order:"
"级数展开式包含了近似的阶数,当我们对不同阶数的级数展开式进行计算时,这对于跟踪有效性的阶数非常有用:"
] ]
}, },
{ {
@@ -2001,7 +2001,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"If we want to get rid of the order information we can use the `removeO` method:"
"如果我们想摆脱阶数信息,我们可以使用`removeO`方法:"
] ]
}, },
{ {
@@ -2035,7 +2035,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"But note that this is not the correct expansion of $\\cos(x)\\sin(x)$ to $5$th order:"
"但请注意,这不是$\\cos(x)\\sin(x)$到$5$的正确扩展:"
] ]
}, },
{ {
@@ -2069,21 +2069,21 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Linear algebra"
"## 9. 线性代数"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"### Matrices"
"### 9.1 矩阵"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Matrices are defined using the `Matrix` class:"
"使用`Matrix`类可以定义矩阵:"
] ]
}, },
{ {
@@ -2154,7 +2154,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"With `Matrix` class instances we can do the usual matrix algebra operations:"
"有`Matrix`类实例的基础上我们可以做常规的矩阵代数运算:"
] ]
}, },
{ {
@@ -2215,7 +2215,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"And calculate determinants and inverses, and the like:"
"计算行列式和逆,诸如此类:"
] ]
}, },
{ {
@@ -2276,14 +2276,14 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Solving equations"
"## 10. 求解方程"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"For solving equations and systems of equations we can use the `solve` function:"
"对于求解方程和方程组我们可以用`solve`函数:"
] ]
}, },
{ {
@@ -2348,7 +2348,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"System of equations:"
"方程组:"
] ]
}, },
{ {
@@ -2379,7 +2379,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"In terms of other symbolic expressions:"
"在其他符号表达方面:"
] ]
}, },
{ {
@@ -2412,7 +2412,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Further reading"
"## 11. 进一步的阅读"
] ]
}, },
{ {
@@ -2428,7 +2428,7 @@
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## Versions"
"## 12. 版本"
] ]
}, },
{ {


Loading…
Cancel
Save