summaryrefslogtreecommitdiff
path: root/LectureNotesOnPython.rst
diff options
context:
space:
mode:
authorHui Lan <lanhui@zjnu.edu.cn>2019-07-29 18:20:49 +0800
committerHui Lan <lanhui@zjnu.edu.cn>2019-07-29 18:20:49 +0800
commit6a1bb3037d35b9d14fa21d9f27f8d444188b208d (patch)
tree56b377cc98a3a37b7298a38cad3fe9b7ab91e452 /LectureNotesOnPython.rst
parente5742d13c8bfe196d57b80418294f765e3cc44a0 (diff)
LectureNotesOnPython.rst: 初学者容易犯的错误
Diffstat (limited to 'LectureNotesOnPython.rst')
-rw-r--r--LectureNotesOnPython.rst12
1 files changed, 12 insertions, 0 deletions
diff --git a/LectureNotesOnPython.rst b/LectureNotesOnPython.rst
index 174bff0..61dd22a 100644
--- a/LectureNotesOnPython.rst
+++ b/LectureNotesOnPython.rst
@@ -427,6 +427,18 @@ a是变量名。 'a'是值。 a = 'a' 这个语句要从右边向左边读,
这很正常。 编程要达到一定的代码量, 才能渐渐感觉清晰。 你的第一个目标是100行代码, 实现这个目标后下一个目标是500行代码, 当你的代码量超过1000行时, 很多问题会渐渐清晰。 出错也很正常, 认识到错误的原因, 把错误改正了, 就等于进步了。
+**练习** 以下是初学者写的代码, 反应了初学者容易出错的地方。 指出每个语句的错误所在。
+
+
+- x.upper # 函数忘记加括号, 应该是 x.upper()
+
+- t = my*999 #字符串忘记加单引号, 应该是 t = 'my' * 999
+
+- t=my*999 # 等号前后没有空格 (编程风格差), 应该是 t = 'my' * 999
+
+
+
+
**练习** 把下面这段文字转成字符串并存在变量boris中。
Boris Johnson, Prime Minister of the United Kingdom. Alexander Boris de Pfeffel Johnson is a British politician serving as Prime Minister of the United Kingdom and Leader of the Conservative Party since July 2019. He has been the Member of Parliament for Uxbridge and South Ruislip since 2015 and was the MP for Henley from 2001 to 2008. He also served as Mayor of London from 2008 to 2016 and Foreign Secretary from 2016 to 2018. Johnson identifies as a one-nation conservative and has been associated with both economically and socially liberal policies.