Skip to content

Commit fadf255

Browse files
committed
创建中文Python笔记
0 parents  commit fadf255

127 files changed

Lines changed: 71551 additions & 0 deletions

File tree

Some content is hidden

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

.gitattibutes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# encoding=UTF-8

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*/.ipynb_checkpoints/*
2+
/.ipynb_checkpoints/*
3+
*-checkpoint.ipynb
4+
*.pyc
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"collapsed": true
7+
},
8+
"source": [
9+
"# Python简介"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"##**Python**历史"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"Python的创始人为荷兰人吉多·范罗苏姆(Guido van Rossum)。1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言的一种继承。之所以选中Python作为程序的名字,是因为他是BBC电视剧——蒙提·派森的飞行马戏团(Monty Python's Flying Circus)的爱好者。\n",
24+
"\n",
25+
"1991年,第一个Python编译器诞生。它是用C语言实现的,并能够调用C语言的库文件。\n",
26+
"\n",
27+
"Python 2.0于2000年10月16日发布,增加了实现完整的垃圾回收,并且支持Unicode。\n",
28+
"\n",
29+
"Python 3.0于2008年12月3日发布,此版不完全兼容之前的Python源代码。不过,很多新特性后来也被移植到旧的Python 2.6/2.7版本。"
30+
]
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"metadata": {},
35+
"source": [
36+
"##第一行Python代码"
37+
]
38+
},
39+
{
40+
"cell_type": "markdown",
41+
"metadata": {},
42+
"source": [
43+
"安装好Python之后,在命令行下输入:\n",
44+
"\n",
45+
" python\n",
46+
"\n",
47+
"就可以进入Python解释器的页面。\n",
48+
"\n",
49+
"按照惯例,第一行代码应该是输出 `\"hello world!\"`:"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 1,
55+
"metadata": {
56+
"collapsed": false
57+
},
58+
"outputs": [
59+
{
60+
"name": "stdout",
61+
"output_type": "stream",
62+
"text": [
63+
"hello world!\n",
64+
"hello world!\n"
65+
]
66+
}
67+
],
68+
"source": [
69+
"print \"hello world!\""
70+
]
71+
},
72+
{
73+
"cell_type": "markdown",
74+
"metadata": {},
75+
"source": [
76+
"相对**Java**,**C**等语言来说,**Python**仅仅使用一行语句就完成的了这个任务。\n",
77+
"\n",
78+
"可以将这句话的内容保存到一个文本文件中,并使用后缀名 `.py` 结尾,例如 `hello_world.py`,在命令行下运行这个程序:\n",
79+
"\n",
80+
" python hello_world.py\n",
81+
"\n",
82+
"也会输出 `\"hello world!\"` 的结果。"
83+
]
84+
},
85+
{
86+
"cell_type": "markdown",
87+
"metadata": {},
88+
"source": [
89+
"## Python之禅"
90+
]
91+
},
92+
{
93+
"cell_type": "markdown",
94+
"metadata": {},
95+
"source": [
96+
"在**Python**解释器下输入 `import this`,会出来这样一首小诗:"
97+
]
98+
},
99+
{
100+
"cell_type": "code",
101+
"execution_count": 2,
102+
"metadata": {
103+
"collapsed": false
104+
},
105+
"outputs": [
106+
{
107+
"name": "stdout",
108+
"output_type": "stream",
109+
"text": [
110+
"The Zen of Python, by Tim Peters\n",
111+
"\n",
112+
"Beautiful is better than ugly.\n",
113+
"Explicit is better than implicit.\n",
114+
"Simple is better than complex.\n",
115+
"Complex is better than complicated.\n",
116+
"Flat is better than nested.\n",
117+
"Sparse is better than dense.\n",
118+
"Readability counts.\n",
119+
"Special cases aren't special enough to break the rules.\n",
120+
"Although practicality beats purity.\n",
121+
"Errors should never pass silently.\n",
122+
"Unless explicitly silenced.\n",
123+
"In the face of ambiguity, refuse the temptation to guess.\n",
124+
"There should be one-- and preferably only one --obvious way to do it.\n",
125+
"Although that way may not be obvious at first unless you're Dutch.\n",
126+
"Now is better than never.\n",
127+
"Although never is often better than *right* now.\n",
128+
"If the implementation is hard to explain, it's a bad idea.\n",
129+
"If the implementation is easy to explain, it may be a good idea.\n",
130+
"Namespaces are one honking great idea -- let's do more of those!\n",
131+
"The Zen of Python, by Tim Peters\n",
132+
"\n",
133+
"Beautiful is better than ugly.\n",
134+
"Explicit is better than implicit.\n",
135+
"Simple is better than complex.\n",
136+
"Complex is better than complicated.\n",
137+
"Flat is better than nested.\n",
138+
"Sparse is better than dense.\n",
139+
"Readability counts.\n",
140+
"Special cases aren't special enough to break the rules.\n",
141+
"Although practicality beats purity.\n",
142+
"Errors should never pass silently.\n",
143+
"Unless explicitly silenced.\n",
144+
"In the face of ambiguity, refuse the temptation to guess.\n",
145+
"There should be one-- and preferably only one --obvious way to do it.\n",
146+
"Although that way may not be obvious at first unless you're Dutch.\n",
147+
"Now is better than never.\n",
148+
"Although never is often better than *right* now.\n",
149+
"If the implementation is hard to explain, it's a bad idea.\n",
150+
"If the implementation is easy to explain, it may be a good idea.\n",
151+
"Namespaces are one honking great idea -- let's do more of those!\n"
152+
]
153+
}
154+
],
155+
"source": [
156+
"import this"
157+
]
158+
},
159+
{
160+
"cell_type": "markdown",
161+
"metadata": {},
162+
"source": [
163+
"这首诗反映了**Python**的设计哲学——**Python**是一种追求优雅,明确,简单的编程语言,但事实上,产生这首诗的代码并没有写的那么简单易懂:"
164+
]
165+
},
166+
{
167+
"cell_type": "code",
168+
"execution_count": 3,
169+
"metadata": {
170+
"collapsed": false
171+
},
172+
"outputs": [
173+
{
174+
"name": "stdout",
175+
"output_type": "stream",
176+
"text": [
177+
"The Zen of Python, by Tim Peters\n",
178+
"\n",
179+
"Beautiful is better than ugly.\n",
180+
"Explicit is better than implicit.\n",
181+
"Simple is better than complex.\n",
182+
"Complex is better than complicated.\n",
183+
"Flat is better than nested.\n",
184+
"Sparse is better than dense.\n",
185+
"Readability counts.\n",
186+
"Special cases aren't special enough to break the rules.\n",
187+
"Although practicality beats purity.\n",
188+
"Errors should never pass silently.\n",
189+
"Unless explicitly silenced.\n",
190+
"In the face of ambiguity, refuse the temptation to guess.\n",
191+
"There should be one-- and preferably only one --obvious way to do it.\n",
192+
"Although that way may not be obvious at first unless you're Dutch.\n",
193+
"Now is better than never.\n",
194+
"Although never is often better than *right* now.\n",
195+
"If the implementation is hard to explain, it's a bad idea.\n",
196+
"If the implementation is easy to explain, it may be a good idea.\n",
197+
"Namespaces are one honking great idea -- let's do more of those!\n",
198+
"The Zen of Python, by Tim Peters\n",
199+
"\n",
200+
"Beautiful is better than ugly.\n",
201+
"Explicit is better than implicit.\n",
202+
"Simple is better than complex.\n",
203+
"Complex is better than complicated.\n",
204+
"Flat is better than nested.\n",
205+
"Sparse is better than dense.\n",
206+
"Readability counts.\n",
207+
"Special cases aren't special enough to break the rules.\n",
208+
"Although practicality beats purity.\n",
209+
"Errors should never pass silently.\n",
210+
"Unless explicitly silenced.\n",
211+
"In the face of ambiguity, refuse the temptation to guess.\n",
212+
"There should be one-- and preferably only one --obvious way to do it.\n",
213+
"Although that way may not be obvious at first unless you're Dutch.\n",
214+
"Now is better than never.\n",
215+
"Although never is often better than *right* now.\n",
216+
"If the implementation is hard to explain, it's a bad idea.\n",
217+
"If the implementation is easy to explain, it may be a good idea.\n",
218+
"Namespaces are one honking great idea -- let's do more of those!\n"
219+
]
220+
}
221+
],
222+
"source": [
223+
"s = \"\"\"Gur Mra bs Clguba, ol Gvz Crgref\n",
224+
"\n",
225+
"Ornhgvshy vf orggre guna htyl.\n",
226+
"Rkcyvpvg vf orggre guna vzcyvpvg.\n",
227+
"Fvzcyr vf orggre guna pbzcyrk.\n",
228+
"Pbzcyrk vf orggre guna pbzcyvpngrq.\n",
229+
"Syng vf orggre guna arfgrq.\n",
230+
"Fcnefr vf orggre guna qrafr.\n",
231+
"Ernqnovyvgl pbhagf.\n",
232+
"Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.\n",
233+
"Nygubhtu cenpgvpnyvgl orngf chevgl.\n",
234+
"Reebef fubhyq arire cnff fvyragyl.\n",
235+
"Hayrff rkcyvpvgyl fvyraprq.\n",
236+
"Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.\n",
237+
"Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.\n",
238+
"Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.\n",
239+
"Abj vf orggre guna arire.\n",
240+
"Nygubhtu arire vf bsgra orggre guna *evtug* abj.\n",
241+
"Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.\n",
242+
"Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.\n",
243+
"Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!\"\"\"\n",
244+
"\n",
245+
"d = {}\n",
246+
"for c in (65, 97):\n",
247+
" for i in range(26):\n",
248+
" d[chr(i+c)] = chr((i+13) % 26 + c)\n",
249+
"\n",
250+
"print \"\".join([d.get(c, c) for c in s])"
251+
]
252+
},
253+
{
254+
"cell_type": "markdown",
255+
"metadata": {},
256+
"source": [
257+
"> Life is short. Use Python."
258+
]
259+
}
260+
],
261+
"metadata": {
262+
"kernelspec": {
263+
"display_name": "Python 2",
264+
"language": "python",
265+
"name": "python2"
266+
},
267+
"language_info": {
268+
"codemirror_mode": {
269+
"name": "ipython",
270+
"version": 2
271+
},
272+
"file_extension": ".py",
273+
"mimetype": "text/x-python",
274+
"name": "python",
275+
"nbconvert_exporter": "python",
276+
"pygments_lexer": "ipython2",
277+
"version": "2.7.10"
278+
}
279+
},
280+
"nbformat": 4,
281+
"nbformat_minor": 0
282+
}

0 commit comments

Comments
 (0)