目录
2. Computer hardware structure
5 Writing a program using a text editor (Atom)
6 The building blocks of programs
1. Learning materials
python for everybody book:PY4E - Python for Everybody
coursera 课程: Python for Everybody | Coursera
python下载:Download Python | Python.org
文本编辑器下载:Atom
2. Computer hardware structure
▲Central Processing Unit (CPU):“询问”Wha's next并迅速执行命令
▲main memory:暂时储存CPU所需的数据,速度和CPU接近,关机后则清除
▲secondary memory:长期储存数据,速度慢(如USB盘)
▲input and output device:与电脑交互的屏幕、鼠标、键盘等
▲network connection:相当于一个更慢且更不可靠的secondary memory
As a programmer you will mostly be “talking” to the CPU and telling it what to do next. Sometimes you will tell the CPU to use the main memory, secondary memory, network, or the input/output devices.
程序员:回答CPU的“what‘s next",给出指令
We call these stored instructions a program and the act of writing these instructions down and getting the instructions to be correct programming.
程序:储存的指令
编程:正确编写指令
3 Words and sentence
▲ reserved words: 对于python具有独特意义的词
and as assert break class continue def
del elif else except finally for from
global if import in is lambda nonlocal
not or pass raise return try while
with yield
▲ variables:自己命名的变量用于标记需要储存的数据,不能使用reserved words,不同的变量名对python没有任何区别,但好的变量名能帮助编程者理解程序
>>> x = 6
>>> print(x)
6
>>> y = x * 7
>>> print(y)
42
>>>
▲ sentence:如:
print('Jackson Yee!')
4 Coversing with python
1. 安装好python后打开搜索栏搜索命令提示符(command)
2.输入python之后出现>>>,即表示进入与python”对话“模式
Microsoft Windows [版本 10.0.19042.1288]
(c) Microsoft Corporation。保留所有权利。
C:\Users\123>python
Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('Jackson Yee!')
Jackson Yee!
>>>
3. 当输入python无法理解的语句时就会出现syntax error,退出python用quit()
>>> good bye!
File "<stdin>", line 1
good bye!
^^^^^^^^
SyntaxError: invalid syntax. Perhaps you forgot a comma?
>>> quit()
C:\Users\123>
5 Writing a program using a text editor (Atom)
当需要解决一个复杂问题时,需要写多行代码,采用Atom编写成一个.py文件后执行
1.Atom 界面
2. File-new file新建文档
3. File-Save as成一个后缀.py的文件后自动识别python的语句特点(如reserved words用颜色区分)
4. 保存后即可通过command命令提示符运行整个文件 python xxx.py
C:\Users\123>cd desktop/python ###打开.py文件所在位置
C:\Users\123\Desktop\python>python example.py ###python xxx.py运行
Jackson Yee
Glitter Forever!
C:\Users\123\Desktop\python>
6 The building blocks of programs
一个程序的基本构成要素:
▲input:从外部获取数据
▲output:展示运行结果
▲sequential execution:按顺序执行语句命令
▲conditional execution:检查是否满足某项条件,满足则执行,不满足则跳过
▲repeated execution:重复执行某些命令
▲reuse:将一些命令写一遍后保存,并在整个程序中重复调用该命令
7 Python errors
▲syntax errors:语法错误,最常遇见的错误,python会告知你在第几行出现错误,以及可能的原因
▲logic errors:逻辑错误
▲semantic errors:指令无法实现目标