File tree Expand file tree Collapse file tree 3 files changed +14
-24
lines changed
Expand file tree Collapse file tree 3 files changed +14
-24
lines changed Original file line number Diff line number Diff line change @@ -159,7 +159,7 @@ export default sidebar({
159159 text : "Review" ,
160160 icon : "idea" ,
161161 children : [
162-
162+ "03" ,
163163 ]
164164 }
165165 ] ,
Original file line number Diff line number Diff line change @@ -25,42 +25,32 @@ toc: true
2525
2626环境配置好后,我们就来快速学习几个 Python 必会的基础语法。我假设你是 Python 零基础,但已经有一些其他编程语言的基础。下面我们一一来看。
2727
28- ### 2.1 输入与输出
28+ ## 1. 输入与输出
2929
3030``` python
31- name = raw_input (" What's your name?" )
32- sum = 100 + 100
33- print (' hello,%s ' % name)
34- print (' sum = %d ' % sum )
35- ```
36-
37- ` raw_input ` 是 Python2.7 的输入函数,在 python3.x 里可以直接使用 input,赋值给变量 name,print 是输出函数,` %name ` 代表变量的数值,因为是字符串类型,所以在前面用的 ` %s ` 作为代替。
38-
39- 这是运行结果:
40-
41- ``` python
42- What' s your name?cy
43- hello,cy
44- sum = 200
31+ name = input (" What's your name?" )
32+ sum1 = 100 + 100
33+ print (' hello,' , name)
34+ print (' sum = ' , sum1)
4535```
4636
4737
4838
4939### 2.2 判断语句:if … else …
5040
5141``` python
52- if score>= 90 :
53- print ' Excellent'
42+ if score >= 90 :
43+ print ( ' Excellent' )
5444else :
55- if score < 60 :
56- print ' Fail'
57- else :
58- print ' Good Job'
45+ if score < 60 :
46+ print ( ' Fail' )
47+ else :
48+ print ( ' Good Job' )
5949```
6050
6151if … else … 是经典的判断语句,需要注意的是在 if expression 后面有个冒号,同样在 else 后面也存在冒号。
6252
63- 另外需要注意的是,Python 不像其他语言一样使用{} 或者 begin…end 来分隔代码块,而是采用代码缩进和冒号的方式来区分代码之间的层次关系。所以** 代码缩进在 Python 中是一种语法** ,如果代码缩进不统一,比如有的是 tab 有的是空格,会怎样呢?会产生错误或者异常。相同层次的代码一定要采用相同层次的缩进。
53+ 另外需要注意的是,Python 不像其他语言一样使用 ` {} ` 或者 begin…end 来分隔代码块,而是采用代码缩进和冒号的方式来区分代码之间的层次关系。所以** 代码缩进在 Python 中是一种语法** ,如果代码缩进不统一,比如有的是 tab 有的是空格,会怎样呢?会产生错误或者异常。相同层次的代码一定要采用相同层次的缩进。
6454
6555### 2.3 循环语句:for … in
6656
Original file line number Diff line number Diff line change @@ -100,7 +100,7 @@ In [137]: %save aiyc.py 1-135
100100
101101例如,这允许引用较早的会话,例如
102102
103- ``` dpython
103+ ``` python
104104% save current_session ~ 0 /
105105% save previous_session ~ 1 /
106106```
You can’t perform that action at this time.
0 commit comments