Skip to content

Commit ea07a51

Browse files
committed
..
1 parent 71c7b8e commit ea07a51

14 files changed

+233
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Python 核心编程-2017-8-1-The Zen of Python
2+
3+
>>>import this
4+
5+
> Beautiful is better than ugly.
6+
>
7+
> Explicit is better than implicit.
8+
>
9+
> Simple is better than complex.
10+
>
11+
> Complex is better than complicated.
12+
>
13+
> Flat is better than nested.
14+
>
15+
> Sparse is better than dense.
16+
>
17+
> Readability counts.
18+
>
19+
> Special cases aren't special enough to break the rules.
20+
>
21+
> Although practicality beats purity.
22+
>
23+
> Errors should never pass silently.
24+
>
25+
> Unless explicitly silenced.
26+
>
27+
> In the face of ambiguity, refuse the temptation to guess.
28+
>
29+
> There should be one-- and preferably only one --obvious way to do it.
30+
>
31+
> Although that way may not be obvious at first unless you're Dutch.
32+
>
33+
> Now is better than never.Although never is often better than *right* now.
34+
>
35+
> If the implementation is hard to explain, it's a bad idea.
36+
>
37+
> If the implementation is easy to explain, it may be a good idea.
38+
>
39+
> Namespaces are one honking great idea -- let's do more of those!
40+
41+
--- PEP 20
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# 数字
2+

051-number.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# coding:utf-8
2+
3+
# 注意:Python中一切都是对象
4+
# 创建数字对象
5+
anInt = 1
6+
aLong = -999999999999999999L
7+
aFloat = 3.142567273837287372632763726723837837
8+
aComplex = 1.23 + 4.56j
9+
10+
# 更新对象
11+
anInt += 1
12+
aFloat = 2.34747387483
13+
14+
# 删除对象
15+
del anInt
16+
del aLong
17+
18+
# print anInt # 已删除
19+
# print aLong # 已删除
20+
print aFloat # 已更新
21+
print aComplex
22+
# -------------------------------------------------
23+
24+
# 整型包括:布尔型,标准整形,长整形
25+
# 整型支持:八进制(以“0”开头),十进制,十六进制(以“0x”开头)
26+
ai = 0101010
27+
bi = 673
28+
ci = 0x8
29+
di = 74327823L
30+
31+
# 浮点型:Python中的浮点型全部都是双精度浮点型,可以使用十进制或科学计数法来表示。
32+
af = 0.0
33+
bf = -777.
34+
cf = 3.893
35+
ef = 67e3
36+
ff = float(34)
37+
38+
# 复数:复数由实数部和虚数部构成,虚数单位为j
39+
# 表示为:real+imagej
40+
# 实数部和虚数部都是浮点数
41+
ac = 783.3+821.32j
42+
bc = 326.32-73.32j
43+
cc = -56.23-635.3j
44+
dc = -.004+0j
45+
# 复数的内建属性:real,image,conjugate 共轭复数
46+
ec = -8.333-2.99j
47+
print ec.real
48+
print ec.imag
49+
print ec.conjugate() # 返回共轭复数
50+
# -------------------------------------------------
51+
52+
# 类型转换
53+
# 整型转换为浮点型,非复数型转换为复数型
54+
achange = 3627
55+
bchange = float(achange)
56+
cchange = 28
57+
dchange = complex(28)
58+
print bchange, type(bchange) # <type 'float'>
59+
print dchange, type(dchange) # <type 'complex'>
60+
61+
62+

052-operater.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# coding:utf-8
2+
3+
from __future__ import division
4+
5+
# 操作符
6+
# 算术操作符:+,-,*,/,%,**
7+
# 注意:除法
8+
print 1 / 2
9+
print float(2 / 3)
10+
print 3 % 2
11+
print 7 ** 4
12+
13+
# 位操作符:只适用于整型
14+
# 取反(~),按位与(&),或(|),异或(^),左移(<<),右移(>>)
15+
print ~30
16+
print 78 & -32
17+
print 62 | 82
18+
print 30 ^ 45
19+
print 60 >> 2
20+
print 38 << 3
21+
22+
# 内建函数: cmp(),str(),type()
23+
# 功能内建函数:abs(),coerce(),divmod(),pow(),round()
24+
print cmp(-6, 2)
25+
print cmp(0xff, 255)
26+
print str(632)
27+
print type(0xff)
28+
29+
# 工厂函数:数值工厂函数 int(),float(),long(),complex(),bool()
30+
31+
32+
# 布尔数:在数学运算中,布尔值的True和False分别对应于1和0
33+
34+
# 十进制浮点型:from decimal import Decimal
35+
from decimal import Decimal
36+
dec = Decimal(1.1)
37+
print dec
38+
39+
# 模块:decimal,array,math,operator,random
40+
# 核心模块:random
41+
# |--|--|
42+
# |randint()||
43+
# |randrange()||
44+
# |uniform()||
45+
# |random()||
46+
# |choice()||

053-exercise.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding:utf-8
2+
3+
4+
# 5-2
5+
def mul(a, b):
6+
return a * b
7+
8+
print mul(2, 3)
9+
10+
# 5-3
11+
12+
# 5-4
13+
# 5-5
14+
# 5-6
15+
# 5-7
16+
# 5-8
17+
# 5-9
18+
# 5-10
19+
# 5-11
20+
# 5-12
21+
# 5-13
22+
# 5-14
23+
# 5-15
24+
# 5-16
25+
# 5-17
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+


0 commit comments

Comments
 (0)