summaryrefslogtreecommitdiff
path: root/LectureNotesOnPython.rst
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2019-04-01 08:49:55 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2019-04-01 08:49:55 +0800
commitba3c61624bc224d0c5ef39b3c0f0c9ce6f426786 (patch)
tree3a61bf857da0d0b634402bf200ac47cf9ca07362 /LectureNotesOnPython.rst
parent4ce937568716177d90ffbdde3c8ad1e5e935bc1d (diff)
updated lecture notes
Diffstat (limited to 'LectureNotesOnPython.rst')
-rw-r--r--LectureNotesOnPython.rst37
1 files changed, 36 insertions, 1 deletions
diff --git a/LectureNotesOnPython.rst b/LectureNotesOnPython.rst
index 80e9d5e..3f1e76d 100644
--- a/LectureNotesOnPython.rst
+++ b/LectureNotesOnPython.rst
@@ -987,9 +987,44 @@ key与value互换
练习: 定义一个函数 ``empty_dict`` 清空字典 ``record``。 要求: 不能用 ``return`` 语句。 提示: 可以用 ``pop`` 方法, 或者直接给 ``record`` 赋值 ``{}`` 。
-函数执行顺序
+调用函数与传递参数
~~~~~~~~~~~~~~~~~~~~~~~~~
+在使用函数前要先确定函数已经被定义。
+
+区别 ``argument`` 与 ``parameter`` 。传过去的是 ``argument`` , 函数头的参数列表是 ``parameter`` 。 ``argument`` 的值赋给 ``parameter`` , ``parameter`` 是函数的局部变量。
+
+``argument`` 与 ``parameter`` 的名字可以相同也可以不同。
+
+
+.. code:: python
+
+ def reverse_string(s):
+ t = ''
+ for i in range(len(s)-1,-1,-1):
+ t += s[i]
+ return t
+
+
+
+ s = 'put'
+ t = reverse_string(s)
+ print(t)
+
+以上 s 一个是全局变量一个是局部变量。
+
+以上 t 一个是全局变量一个是局部变量。
+
+
+
+
+函数执行顺序 (flow of execution)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+函数的定义不执行,被调用时才执行。
+
+顺序执行。 当遇到函数调用时,跳转到函数,执行函数,函数返回后继续执行跳转地后一条语句。
+
参考