Skip to content

Commit ee4730e

Browse files
committed
fix 103,104,107�� Add 503
1 parent a2d6a2f commit ee4730e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3598
-211
lines changed

103.md

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
>For I am not ashamed of the gospel; it is the power of God for salvation to everyone who has faith, to the Jew first and also to the Greek. For in it the righteousness of God is revealed through faith for faith; s it is written,"The one who is righteous will live by faith"
2+
13
#用Python计算
24

35
一提到计算机,当然现在更多人把她叫做电脑,这两个词都是指computer。不管什么,只要提到她,普遍都会想到她能够比较快地做加减乘除,甚至乘方开方等。乃至于,有的人在口语中区分不开计算机和计算器。
@@ -13,7 +15,7 @@
1315
>>> print 'Hello, World'
1416
Hello, World
1517

16-
细心的看官,是否注意到,我在这里用的是单引号,[上次](./102.md)用的是双引号。两者效果一样,也就是在这种情况下,单引号和双引号是一样的效果,一定要是成对出现的,不能一半是单引号,另外一半是双引号。
18+
细心的看官,是否注意到,我在这里用的是单引号,[上次](102.md)用的是双引号。两者效果一样,也就是在这种情况下,单引号和双引号是一样的效果,一定要是成对出现的,不能一半是单引号,另外一半是双引号。
1719

1820
##四则运算
1921

@@ -101,10 +103,55 @@ ok!看官可以在IDE中实验一下大整数相乘。
101103
type(988776544222112233445566778899887766554433221133344455566677788998776543222344556678)
102104
<type 'long'> #是长整数,也是一个整数
103105

106+
##几个常见函数
107+
108+
在这里就提到函数,因为这个东西是经常用到的。什么是函数?如果看官不知道此定义,可以去google。貌似是初二数学讲的了。
109+
110+
有几个常用的函数,列一下,如果记不住也不要紧,知道有这些就好了,用的时候就google。
111+
112+
**求绝对值**
113+
114+
>>> abs(10)
115+
10
116+
>>> abs(-10)
117+
10
118+
>>> abs(-1.2)
119+
1.2
120+
121+
**四舍五入**
122+
123+
>>> round(1.234)
124+
1.0
125+
>>> round(1.234,2)
126+
1.23
127+
128+
>>> #如果不清楚这个函数的用法,可以使用下面方法看帮助信息
129+
>>> help(round)
130+
131+
Help on built-in function round in module __builtin__:
132+
133+
round(...)
134+
round(number[, ndigits]) -> floating point number
135+
136+
Round a number to a given precision in decimal digits (default 0 digits).
137+
This always returns a floating point number. Precision may be negative.
138+
139+
**幂函数**
140+
141+
>>> pow(2,3) #2的3次方
142+
8
143+
144+
**math模块**(对于模块可能还有点陌生,不过不要紧,先按照下面代码实验一下,慢慢就理解了)
145+
146+
>>> import math #引入math模块
147+
>>> math.floor(32.8) #取整,不是四舍五入
148+
32.0
149+
>>> math.sqrt(4) #开平方
150+
2.0
151+
152+
104153
##总结
105154

106155
- python里的加减乘除按照小学数学规则执行
107156
- 不用担心大整数问题,python会自动处理
108157
- type(object)是一个有用的东西
109-
110-

104.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
>"I give you a new commandment, that you love one another. Just as I have loved you, you also should love one another. By this everyone will know that you are my disciples, if you have love for one another."(JOHN14:34-35)
2+
13
#啰嗦的除法
24

3-
除法啰嗦的,不仅是python。
5+
除法啰嗦,不仅是python。
46

57
##整数除以整数
68

7-
看官请在启动idle之后,练习下面的运算:
9+
看官请在进入python交互模式之后(以后在本教程中,可能不再重复这类的叙述,只要看到>>>,就说明是在交互模式下,这个交互模式,看官可以在ide中,也可以像我一样直接在shell中运行python进入交互模式),练习下面的运算:
810

911
>>> 2/5
1012
0
@@ -15,9 +17,9 @@
1517
>>> 2.0/5.0
1618
0.4
1719

18-
看到没有?麻烦出来了,如果从小学数学知识除法,以上四个运算结果都应该是0.4。但我们看到的后三个符合,第一个居然结果是0。why?
20+
看到没有?麻烦出来了(这是在python2.x中),如果从小学数学知识除法,以上四个运算结果都应该是0.4。但我们看到的后三个符合,第一个居然结果是0。why?
1921

20-
因为,在python里面有一个规定,像2/5中的除法这样,是要取整。2除以5,商是0(整数),余数是2(整数)。那么如果用这种形式:2/5,计算结果就是商那个整数。或者可以理解为:**整数除以整数,结果是整数(商)**
22+
因为,在python(严格说是python2.x中,python3会有所变化,具体看官要了解,可以去google)里面有一个规定,像2/5中的除法这样,是要取整(就是去掉小数,但不是四舍五入)。2除以5,商是0(整数),余数是2(整数)。那么如果用这种形式:2/5,计算结果就是商那个整数。或者可以理解为:**整数除以整数,结果是整数(商)**
2123

2224
继续实验,验证这个结论:
2325

@@ -40,11 +42,9 @@
4042

4143
##浮点数与整数相除
4244

43-
列为看官注意,这个标题和上面的标题格式不一样,上面的标题是“整数除以整数”,如果按照风格一贯制的要求,本节标题应该是“浮点数除以整数”,但没有,现在是“浮点数与整数相除”,这是因为包含了以下三种情况
45+
列位看官注意,这个标题和上面的标题格式不一样,上面的标题是“整数除以整数”,如果按照风格一贯制的要求,本节标题应该是“浮点数除以整数”,但没有,现在是“浮点数与整数相除”,其含义是
4446

45-
- 被除数是浮点数,除数是整数
46-
- 被除数是整数,除数是浮点数
47-
- 被除数和除数都是浮点数
47+
>假设:x除以y。其中 x 可能是整数,也可能是浮点数;y可能是整数,也可能是浮点数。
4848
4949
出结论之前,还是先做实验:
5050

@@ -83,7 +83,7 @@
8383

8484
python总会要提供多种解决问题的方案的,这是她的风格。
8585

86-
##开始用轮子
86+
##引用模块解决除法--启用轮子
8787

8888
python之所以受人欢迎,一个很重重要的原因,就是轮子多。这是比喻啦。就好比你要跑的快,怎么办?光天天练习跑步是不行滴,要用轮子。找辆自行车,就快了很多。还嫌不够快,再换电瓶车,再换汽车,再换高铁...反正你可以选择的很多。但是,这些让你跑的快的东西,多数不是你自己造的,是别人造好了,你来用。甚至两条腿也是感谢父母恩赐。正是因为轮子多,可以选择的多,就可以以各种不同速度享受了。
8989

@@ -114,7 +114,7 @@ python就是这样,有各种各样别人造好的轮子,我们只需要用
114114

115115
前面计算5/2的时候,商是2,余数是1
116116

117-
余数怎么得到?
117+
余数怎么得到?在python中(其实大多数语言也都是),用`%`符号来取得两个数相除的余数.
118118

119119
实验下面的操作:
120120

@@ -131,7 +131,7 @@ python就是这样,有各种各样别人造好的轮子,我们只需要用
131131

132132
符号:%,就是要得到两个数(可以是整数,也可以是浮点数)相除的余数。
133133

134-
前面说python有很多人见人爱的轮子(模块),她还有丰富的内建函数,也会帮我们做不少事情。例如函数divmod()
134+
前面说python有很多人见人爱的轮子(模块),她还有丰富的内建函数,也会帮我们做不少事情。例如函数`divmod()`
135135

136136
>>> divmod(5,2) #表示5除以2,返回了商和余数
137137
(2, 1)
@@ -142,7 +142,7 @@ python就是这样,有各种各样别人造好的轮子,我们只需要用
142142

143143
##四舍五入
144144

145-
最后一个了,一定要坚持,今天的确有点啰嗦了。要实现四舍五入,很简单,就是内建函数:round()
145+
最后一个了,一定要坚持,今天的确有点啰嗦了。要实现四舍五入,很简单,就是内建函数:`round()`
146146

147147
动手试试:
148148

107.md

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
>And since they did not see fit to acknowledge God, God gave them up to a debased mind and things that should no be done. They were filled with every kind of wickedness, evil, covetousness, malice. Full of envy, murder, strife, deceit, craftiness, they are gossips, slanderers, God-haters, insolent, haughty, boastful, inventors of evil, rebellious toward parents, foolish,faithless, heartless, ruthless. They know God's decree, that those who practice such things deserve to die--yet they not only do them but even applaud others who practice them. (ROMANS 1:28-32)
2+
13
#玩转字符串(1)
24

35
如果对自然语言分类,有很多中分法,比如英语、法语、汉语等,这种分法是最常见的。在语言学里面,也有对语言的分类方法,比如什么什么语系之类的。我这里提出一种分法,这种分法尚未得到广大人民群众和研究者的广泛认同,但是,我相信那句“真理是掌握在少数人的手里”,至少在这里可以用来给自己壮壮胆。
@@ -6,8 +8,8 @@
68

79
把我的这种分法抽象一下:
810

9-
- 一种是:△ + □ = ○
10-
- 另外一种是:△ + □ = △ □
11+
- 一种是:△ +□ = ○
12+
- 另外一种是:△ +□ = △ □
1113

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

@@ -103,8 +105,6 @@
103105

104106
###连接字符串
105107

106-
- 方法1:
107-
108108
在IDLE中按照下面方法操作
109109

110110
>>> a = "老齐"
@@ -117,9 +117,53 @@
117117

118118
这是一种最简单连接两个字符串的方法。注意上面例子的最后一行,怎么出现乱码了?那不是乱码,是字符编码的问题。这个你权当没看见好了。不过的确是看见了。请看官google字符编码就知道了。这里推荐一篇非常好的文章:[字符集和字符编码](http://www.cnblogs.com/skynet/archive/2011/05/03/2035105.html)
119119

120-
>>老齐提示:看官做为学习者,一定要对所学的对象有一种好奇心,比如上面例子中,如果你满足于print c,发现结果跟自己所预料一样,这还远远不够。如果你向下走了一行,就发现一个怪怪的结果了,这就让你在编程路上又前进一大步。所以,要有对世界好奇的心,不断探索、思考和尝试。反正在计算机上尝试,也没有多大成本。最坏的结果是关掉IDLE罢了。
120+
>提示:看官做为学习者,一定要对所学的对象有一种好奇心,比如上面例子中,如果你满足于print c,发现结果跟自己所预料一样,这还远远不够。如果你向下走了一行,就发现一个怪怪的结果了,这就让你在编程路上又前进一大步。所以,要有对世界好奇的心,不断探索、思考和尝试。反正在计算机上尝试,也没有多大成本。最坏的结果是关掉IDLE罢了。
121+
122+
`+`号实现连接,的确比较简单,不过,有时候你会遇到这样的问题:
123+
124+
>>> a = 1989
125+
>>> b = "free"
126+
>>> print b+a
127+
Traceback (most recent call last):
128+
File "<stdin>", line 1, in <module>
129+
TypeError: cannot concatenate 'str' and 'int' objects
130+
131+
抱错了,其错误原因已经打印出来了(一定要注意看打印出来的信息):`cannot concatenate 'str' and 'int' objects`。原来`a`对应的对象是一个`int`类型的,不能将它和`str`对象连接起来。怎么办?
132+
133+
可以用下面三种方法中的任何一种:
121134

122-
对字符串的简单操作暂且到这里,下一篇文章继续,还没完,请明天再来。
135+
>>> print b + `a` #注意,` `是反引号,不是单引号,就是键盘中通常在数字1左边的那个,在英文半角状态下输入的符号
136+
free1989
137+
>>> print b + str(a) #str(a)实现将整数对象转换为字符串对象
138+
free1989
139+
>>> print b + repr(a) #repr(a)与上面的类似
140+
free1989
141+
142+
可能看官看到这个,就要问它们三者之间的区别了。首先明确,repr()和``是一致的,就不用区别了。接下来需要区别的就是repr()和str,一个最简单的区别,repr是函数,str是跟int一样,一种对象类型。不过这么说是不能完全解惑的。幸亏有那好的google让我辈使用,你会找到不少人对这两者进行区分的内容,我推荐这个:
143+
144+
>1. When should i use str() and when should i use repr() ?
145+
>
146+
>Almost always use str when creating output for end users.
147+
>
148+
>repr is mainly useful for debugging and exploring. For example, if you suspect a string has non printing characters in it, or a float has a small rounding error, repr will show you; str may not.
149+
>
150+
>repr can also be useful for for generating literals to paste into your source code. It can also be used for persistence (with ast.literal_eval or eval), but this is rarely a good idea--if you want editable persisted values, something like JSON or YAML is much better, and if you don't plan to edit them, use pickle.
151+
152+
>2.In which cases i can use either of them ?
153+
>
154+
>Well, you can use them almost anywhere. You shouldn't generally use them except as described above.
155+
156+
>3.What can str() do which repr() can't ?
157+
>
158+
>Give you output fit for end-user consumption--not always (e.g., str(['spam', 'eggs']) isn't likely to be anything you want to put in a GUI), but more often than repr.
159+
>
160+
>4.What can repr() do which str() can't
161+
>
162+
>Give you output that's useful for debugging--again, not always (the default for instances of user-created classes is rarely helpful), but whenever possible.
163+
>
164+
>And sometimes give you output that's a valid Python literal or other expression--but you rarely want to rely on that except for interactive exploration.
165+
166+
以上英文内容来源:http://stackoverflow.com/questions/19331404/str-vs-repr-functions-in-python-2-7-5
123167

124168
##Python转义字符
125169

@@ -154,5 +198,3 @@
154198
you can connect me by qq\weibo\gmail
155199

156200
看官自己试试吧。如果有问题,可以联系我解答。
157-
158-

0 commit comments

Comments
 (0)