Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4073024

Browse filesBrowse files
committed
Add 3.13, Delete pic, Change pic to github path
1 parent dd256f2 commit 4073024
Copy full SHA for 4073024

File tree

Expand file treeCollapse file tree

294 files changed

+15028
-13211
lines changed
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

294 files changed

+15028
-13211
lines changed
Open diff view settings
Collapse file

‎101.md‎

Copy file name to clipboardExpand all lines: 101.md
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@
4141
#下载源码,目前最新版本是2.7.8,如果以后换了,可以在下面的命令中换版本号
4242
#源码也可以在网站上下载,具体见前述下载页面
4343
wget http://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
44-
44+
4545
#解压源码包
4646
tar -zxvf Python-2.7.8.tgz
47-
47+
4848
#编译
4949
cd Python-2.7.8
5050
./configure --prefix=/usr/local #指定了目录
@@ -53,10 +53,10 @@
5353
以上步骤,是我从网上找来的,供参考。因为我的机器早就安装了,不想折腾。安装好之后,进入shell,输入python,会看到如下:
5454

5555
qw@qw-Latitude-E4300:~$ python
56-
Python 2.7.6 (default, Nov 13 2013, 19:24:16)
56+
Python 2.7.6 (default, Nov 13 2013, 19:24:16)
5757
[GCC 4.6.3] on linux2
5858
Type "help", "copyright", "credits" or "license" for more information.
59-
>>>
59+
>>>
6060

6161
恭喜你,安装成功了。我用的是python2.7.6,或许你的版本号更高。
6262

Collapse file

‎102.md‎

Copy file name to clipboardExpand all lines: 102.md
+7-7Lines changed: 7 additions & 7 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
都会出现如下内容:
1212

13-
Python 2.7.6 (default, Nov 13 2013, 19:24:16)
13+
Python 2.7.6 (default, Nov 13 2013, 19:24:16)
1414
[GCC 4.6.3] on linux2
1515
Type "help", "copyright", "credits" or "license" for more information.
1616
>>>
@@ -31,11 +31,11 @@
3131
>>> print
3232

3333
#"Hello,World"是打印的内容,注意,量变的双引号,都是英文状态下的。引号不是打印内容,它相当于一个包裹,把打印的内容包起来,统一交给python。
34-
>>> print "Hello, World"
35-
34+
>>> print "Hello, World"
35+
3636
#上面命令执行的结果。python接收到你要求她所做的事情:打印Hello,World,于是她就老老实实地执行这个命令,丝毫不走样。
3737
Hello, World
38-
38+
3939
祝贺,伟大的程序员。
4040

4141
>>笑一笑:有一个程序员,自己感觉书法太烂了,于是立志继承光荣文化传统,购买了笔墨纸砚。在某天,开始练字。将纸铺好,拿起笔蘸足墨水,挥毫在纸上写下了两个打字:Hello World
@@ -56,11 +56,11 @@ IDE的全称是:Integrated Development Environment,简称IDE,也稱為Inte
5656
5757
看不懂,没关系,看图,认识一下,混个脸熟就好了。所谓有图有真相。
5858

59-
![](../Pictures/10201.png)
59+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10201.png)
6060

6161
上面的图显示的是微软的提供的名字叫做Microsoft Visual Studio的IDE。用C#进行编程的程序员都用它。
6262

63-
![](../Pictures/10202.png)
63+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10202.png)
6464

6565
上图是在苹果电脑中出现的名叫XCode的IDE。
6666

@@ -83,7 +83,7 @@ google一下:python IDE,会发现,能够进行python编程的IDE还真的
8383

8484
Windows的朋友操作:“开始”菜单->“所有程序”->“Python 2.x”->“IDLE(Python GUI)”来启动IDLE。启动之后,大概看到这样一个图
8585

86-
![](../Pictures/10203.png)
86+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10203.png)
8787

8888
注意:看官所看到的界面中显示版本跟这个图不同,因为安装的版本区别。大致模样差不多。
8989

Collapse file

‎105.md‎

Copy file name to clipboardExpand all lines: 105.md
+9-9Lines changed: 9 additions & 9 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
操作:File->New window
3232

33-
![](../Pictures/10501.png)
33+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10501.png)
3434

3535
这样,就出现了一个新的操作界面,在这个界面里面,看不到用于输入指令的提示符:>>>,这个界面有点像记事本。说对了,本质上就是一个记事本,只能输入文本,不能直接在里面贴图片。
3636

37-
![](../Pictures/10502.png)
37+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10502.png)
3838

3939
##写两个大字:Hello,World
4040

@@ -46,13 +46,13 @@ Hello,World.是面向世界的标志,所以,写任何程序,第一句一
4646

4747
如下图的样式
4848

49-
![](../Pictures/10503.png)
49+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10503.png)
5050

5151
前面说过了,程序就是指令的集合,现在,这个程序里面,就一条指令。一条指令也可以成为集合。
5252

5353
注意观察,菜单上有一个RUN,点击这个菜单,在下拉的里面选择Run Moudle
5454

55-
![](../Pictures/10504.png)
55+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10504.png)
5656

5757
会弹出对话框,要求把这个文件保存,这就比较简单了,保存到一个位置,看官一定要记住这个位置,并且取个文件名,文件名是以.py为扩展名的。
5858

@@ -66,15 +66,15 @@ Hello,World.是面向世界的标志,所以,写任何程序,第一句一
6666

6767
下图是我保存那个文件的地址,我把那个文件命名为105.py,并保存在一个文件夹中。
6868

69-
![](../Pictures/10505.png)
69+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10505.png)
7070

7171
然后在这个shell里面,输入:python 105.py
7272

7373
上面这句话的含义就是告诉计算机,给我运行一个python语言编写的程序,那个程序文件的名称是105.py
7474

7575
我的计算机我做主。于是它给我乖乖地执行了这条命令。如下图:
7676

77-
![](../Pictures/10506.png)
77+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10506.png)
7878

7979
还在沉默?可以欢呼了,德国队7:1胜巴西对,列看官中,不管是德国队还是巴西队的粉丝,都可以欢呼,因为你在程序员道路上迈出了伟大的第二步。顺便预测一下,本届世界杯最终冠军应该是:中国队。(还有这么扯的吗?)
8080

@@ -85,11 +85,11 @@ Hello,World.是面向世界的标志,所以,写任何程序,第一句一
8585
代码如下:
8686

8787
#coding:utf-8
88-
88+
8989
"""
9090
请计算:19+2*4-8/2
9191
"""
92-
92+
9393
a = 19+2*4-8/2
9494
print a
9595

@@ -99,7 +99,7 @@ Hello,World.是面向世界的标志,所以,写任何程序,第一句一
9999

100100
执行结果如下图:
101101

102-
![](../Pictures/10507.png)
102+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10507.png)
103103

104104
上面代码中,第一行,不能少,本文件是能够输入汉字的,否则汉字无法输入。
105105

Collapse file

‎106.md‎

Copy file name to clipboardExpand all lines: 106.md
+5-5Lines changed: 5 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
函数,从简单到复杂,各式各样。前面提供的维基百科中的函数词条,里面可以做一个概览。但不管什么样子的函数,都可以用下图概括:
1111

12-
![](../Pictures/10601.png)
12+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10601.png)
1313

1414
有初中数学水平都能理解一个大概了。这里不赘述。
1515

@@ -58,7 +58,7 @@
5858
3
5959
>>> c
6060
3
61-
>>>
61+
>>>
6262

6363
说明:
6464

@@ -112,7 +112,7 @@
112112
在IDLE中,File->New window
113113

114114
然后输入如下代码:
115-
115+
116116
#coding:utf-8
117117

118118
def add_function(a,b):
@@ -126,13 +126,13 @@
126126

127127
然后我就进入到那个文件夹,运行这个文件,出现下面的结果,如图:
128128

129-
![](../Pictures/10602.png)
129+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/10602.png)
130130

131131
你运行的结果是什么?如果没有得到上面的结果,你就非常认真地检查代码,是否跟我写的完全一样,注意,包括冒号和空格,都得一样。**冒号和空格很重要。**
132132

133133
下面开始庖丁解牛:
134134

135-
- #coding:utf-8 声明本文件中代码的字符集类型是utf-8格式。初学者如果还不理解,一方面可以去google,另外还可放一放,就先这么抄写下来,以后会讲解。
135+
- \#coding:utf-8声明本 文件中代码的字符集类型是utf-8格式。初学者如果还不理解,一方面可以去google,另外还可放一放,就先这么抄写下来,以后会讲解。
136136
- def add_function(a,b): 这里是函数的开始。在声明要建立一个函数的时候,一定要使用def(def 就是英文define的前三个字母),意思就是告知计算机,这里要声明一个函数;add_function是这个函数名称,取名字是有讲究的,就好比你的名字一样。在python中取名字的讲究就是要有一定意义,能够从名字中看出这个函数是用来干什么的。从add_function这个名字中,是不是看出她是用来计算加法的呢?(a,b)这个括号里面的是这个函数的参数,也就是函数变量。冒号,这个冒号非常非常重要,如果少了,就报错了。冒号的意思就是下面好开始真正的函数内容了。
137137
- c=a+b 特别注意,这一行比上一行要缩进四个空格。这是python的规定,要牢记,不可丢掉,丢了就报错。然后这句话就是将两个参数(变量)相加,结果赋值与另外一个变量c。
138138
- print c 还是提醒看官注意,缩进四个空格。将得到的结果c的值打印出来。
Collapse file

‎107.md‎

Copy file name to clipboardExpand all lines: 107.md
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
把我的这种分法抽象一下:
88

9-
- 一种是:△ +□ = ○
10-
- 另外一种是:△ +□ = △ □
9+
- 一种是:△ + □ = ○
10+
- 另外一种是:△ + □ = △ □
1111

1212
我们的语言中,离不开以上两类,不是第一类就是第二类。
1313

@@ -44,7 +44,7 @@
4444

4545
>>> print "小明说:\"我没有少圆明园\""
4646
小明说"我没有少圆明园"
47-
47+
4848
这个例子中,为了打印出那句含有双引号的字符串,也就是双引号是字符串的一部分了,使用了一个符号:\,在python中,将这个符号叫做转义符。本来双引号表示包括字符串,它不是字符串一部分,但是如果前面有转义符,那么它就失去了原来的含义,转化为字符串的一部分,相当于一个特殊字符了。
4949

5050
下面用转义符在打印第二句话:
@@ -114,7 +114,7 @@
114114
老齐教python
115115
>>> c
116116
'\xe8\x80\x81\xe9\xbd\x90\xe6\x95\x99python'
117-
117+
118118
这是一种最简单连接两个字符串的方法。注意上面例子的最后一行,怎么出现乱码了?那不是乱码,是字符编码的问题。这个你权当没看见好了。不过的确是看见了。请看官google字符编码就知道了。这里推荐一篇非常好的文章:[字符集和字符编码](http://www.cnblogs.com/skynet/archive/2011/05/03/2035105.html)
119119

120120
>>老齐提示:看官做为学习者,一定要对所学的对象有一种好奇心,比如上面例子中,如果你满足于print c,发现结果跟自己所预料一样,这还远远不够。如果你向下走了一行,就发现一个怪怪的结果了,这就让你在编程路上又前进一大步。所以,要有对世界好奇的心,不断探索、思考和尝试。反正在计算机上尝试,也没有多大成本。最坏的结果是关掉IDLE罢了。
Collapse file

‎108.md‎

Copy file name to clipboardExpand all lines: 108.md
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@
7878
>>> a="hello"
7979
>>> len(a)
8080
5
81-
81+
8282
使用的是一个函数len(object)。得到的结果就是该字符串长度。
83-
83+
8484
>>> m = len(a) #把结果返回后赋值给一个变量
8585
>>> m
8686
5
@@ -98,11 +98,11 @@
9898
- S.capitalize() #首字母大写
9999
- S.istitle() #单词首字母是否大写的,且其它为小写,****网友白羽毛指出,这里表述不准确。非常感谢他。为了让看官对这些大小写问题有更深刻理解,我从新写下面的例子,请看官审查。再次感谢白羽毛。
100100
- S.isupper() #S中的字母是否全是大写
101-
- S.islower() #S中的字母是否全是小写
101+
- S.islower() #S中的字母是否全是小写
102102

103103
看例子:
104104

105-
>>> a = "qiwsir,python"
105+
>>> a = "qiwsir,python"
106106
>>> a.upper() #将小写字母完全变成大写字母
107107
'QIWSIR,PYTHON'
108108
>>> a #原数据对象并没有改变
Collapse file

‎109.md‎

Copy file name to clipboardExpand all lines: 109.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Hello,wor ld
106106
下面共同做一个练习:输入用户名,计算机自动向这个用户打招呼。代码如下:
107107

108108
#coding:utf-8
109-
109+
110110
print "please write your name:"
111111
name=raw_input()
112112
print "Hello,%s"%name
Collapse file

‎110.md‎

Copy file name to clipboardExpand all lines: 110.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ or,翻译为“或”运算。在A and B中,它是这么运算的:
154154
上面这段算是伪代码啦。所谓伪代码,就是不是真正的代码,无法运行。但是,伪代码也有用途,就是能够以类似代码的方式表达一种计算过程。
155155

156156
看官是不是能够看懂上面的伪代码呢?下面再增加上每行的注释。这个伪代码跟自然的英语差不多呀。
157-
157+
158158
if A==True: #如果A的值是True
159159
return True #返回True,表达式最终结果是True
160160
else: #否则,也就是A的值不是True
Collapse file

‎111.md‎

Copy file name to clipboardExpand all lines: 111.md
+8-8Lines changed: 8 additions & 8 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@
5757

5858
从这里开始,我们的代码就要越来越接近于一个复杂的判断过程了。为了让我们的思维能够更明确上述问题的解决流程,在程序开发过程中,常常要画流程图。什么是流程图,我从另外一个角度讲,就是要让思维过程可视化,简称“思维可视化”。顺便自吹自擂一下,我从2004年就开始在我朝推广思维导图,这就是一种思维可视化工具。自吹到此结束。看这个问题的流程图:
5959

60-
![](../Pictures/11101.png)
60+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/11101.png)
6161

6262
理解了流程图中的含义,就开始写代码,代码实例如下:
63-
63+
6464
#! /usr/bin/env python
6565
#coding:utf-8
66-
66+
6767
print "请输入任意一个整数数字:"
68-
68+
6969
number = int(raw_input()) #通过raw_input()输入的数字是字符串
7070
#用int()将该字符串转化为整数
71-
71+
7272
if number == 10:
7373
print "您输入的数字是:%d"%number
7474
print "You are SMART."
@@ -79,13 +79,13 @@
7979
print "您输入的数字是:%d"%number
8080
print "This number is less than 10."
8181
else:
82-
print "Are you a human?"
83-
82+
print "Are you a human?"
83+
8484
特别提醒看官注意,前面我们已经用过raw_input()函数了,这个是获得用户在界面上输入的信息,而通过它得到的是字符串类型的数据。可以在IDLE中这样检验一下:
8585

8686
>>> a=raw_input()
8787
10
88-
>>> a
88+
>>> a
8989
'10'
9090
>>> type(a)
9191
<type 'str'>
Collapse file

‎112.md‎

Copy file name to clipboardExpand all lines: 112.md
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
另外一个实验室就是UNIX操作系统(包含各种Linux和Mac OSx)的shell,在打开shell之后,输入python,出现如下图所示:
1616

17-
![](../Pictures/11201.png)
17+
![](https://raw.githubusercontent.com/qiwsir/ITArticles/master/Pictures/11201.png)
1818

1919
如果看官是用windows的,也能够通过cmd来获得上图类似的界面,依然是输入python,之后得到界面。
2020

@@ -42,7 +42,7 @@
4242

4343
>>> if bool(a):
4444
... print "I like python"
45-
...
45+
...
4646
I like python
4747

4848
对于if语句,在上一讲[《从if开始语句的征程》](./111.md)中,已经注意到,if下面的执行语句要缩进四个空格。在有的python教材中,说在交互模式下不需要缩进,可能是针对python3或者其它版本,我使用的是python2.7,的确需要缩进。上面的例子就看出来了。
@@ -63,7 +63,7 @@
6363
print "I like python"
6464
^
6565
IndentationError: expected an indented block
66-
66+
6767
从错误信息中,我们可以知道,第二行错了。错在什么地方呢?python非常人性化就在这里,告诉你错误在什么地方:
6868

6969
IndentationError: expected an indented block
@@ -94,7 +94,7 @@ IndentationError: expected an indented block
9494
False
9595
>>> type(m)
9696
<type 'bool'>
97-
>>>
97+
>>>
9898

9999
从上面的实验可以看出,如果对象是空,返回False,如果不是,则返回True;如果对象是False,返回False。上面探索,还可以扩展到其它情况。看官能不能通过探索,总结出bool()的特点呢?
100100

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.