1+ {
2+ "metadata" : {
3+ "name" : " \u9762\u8bd5\u4e2d\u9047\u5230\u7684\u95ee\u9898\u4eec\u2026\u2026 "
4+ },
5+ "nbformat" : 2 ,
6+ "worksheets" : [
7+ {
8+ "cells" : [
9+ {
10+ "cell_type" : " code" ,
11+ "collapsed" : false ,
12+ "input" : [
13+ " # list\u7684\u62f7\u8d1d\u4e0e\u5206\u7247 " ,
14+ " list1 = ['a','b','c','d','e']" ,
15+ " list2 = list1" ,
16+ " list1[1] = 'xxx'" ,
17+ " print \" list1: id=\" ,id(list1), \" value=\" , list1" ,
18+ " print \" list2: id=\" ,id(list2), \" value=\" , list2" ,
19+ " # \u8bf4\u660e\uff1a python\u666e\u901a\u7684\u62f7\u8d1d\u53ea\u662f\u521b\u5efa\u539f\u59cb\u5bf9\u8c61\u7684\u4e00\u4e2a\u5f15\u7528\u3002 " ,
20+ " # \u56e0\u6b64\uff0c\u5f53\u5bf9 a\u505a\u4e86\u4efb\u4f55\u6539\u52a8\u90fd\u4f1a\u76f4\u63a5\u5f71\u54cd\u5230 b\u3002 " ,
21+ " # \u4ece id\u4e5f\u53ef\u4ee5\u770b\u5230\uff0c a\u548c b\u6307\u5411\u7684\u662f\u5b8c\u5168\u4e00\u6837\u7684\u5bf9\u8c61\u3002 " ,
22+ " print list1[10:]" ,
23+ " # \u8bf4\u660e\uff1a\u5217\u8868\u7684\u5207\u7247\u64cd\u4f5c\u4e2d\uff0c\u82e5 begin/end index\u8d85\u51fa\u4e86\u5217\u8868\u7684 index\u8303\u56f4\uff0c " ,
24+ " # \u4e0d\u4f1a\u8fd4\u56de IndexError\uff0c\u800c\u662f\u4f1a\u8fd4\u56de\u4e00\u4e2a\u7a7a\u7684\u5217\u8868 "
25+ ],
26+ "language" : " python" ,
27+ "outputs" : [
28+ {
29+ "output_type" : " stream" ,
30+ "stream" : " stdout" ,
31+ "text" : [
32+ " list1: id= 41922608 value= ['a', 'xxx', 'c', 'd', 'e']" ,
33+ " list2: id= 41922608 value= ['a', 'xxx', 'c', 'd', 'e']" ,
34+ " []"
35+ ]
36+ }
37+ ],
38+ "prompt_number" : 6
39+ },
40+ {
41+ "cell_type" : " code" ,
42+ "collapsed" : false ,
43+ "input" : [
44+ " # \u53c2\u6570\u7c7b\u578b\u53ca\u5176\u533a\u522b " ,
45+ " # \u89c1\uff1a https://github.com/ictar/pythondocument/blob/master/Python%20Common/3.5.1/glossary.md#\u53c2\u6570 argument" ,
46+ " # \u4e5f\u89c1\uff1a https://github.com/ictar/pythondocument/blob/master/Python%20Common/3.5.1/glossary.md#\u53c2\u6570 parameter" ,
47+ " addi = lambda a,b : a + b" ,
48+ " # 1. \u5173\u952e\u5b57\u53c2\u6570\uff1a\u51fd\u6570\u8c03\u7528\u524d\u9762\u6709\u4e00\u4e2a\u6807\u8bc6\u7b26\u7684\u53c2\u6570\u6216\u8005\u503c\u901a\u8fc7\u5728\u5b57\u5178\u524d\u52a0 **\u4f20\u9012\u7684\u53c2\u6570\u3002\u4f8b\u5982 " ,
49+ " print addi(a=3,b=5)" ,
50+ " print addi(**{'a':3,'b':5})" ,
51+ " # 2. \u4f4d\u7f6e\u53c2\u6570\uff1a\u4e0d\u662f\u5173\u952e\u5b57\u53c2\u6570\u7684\u53c2\u6570\u3002 " ,
52+ " # \u4f4d\u7f6e\u53c2\u6570\u53ef\u4ee5\u51fa\u73b0\u5728\u53c2\u6570\u5217\u8868\u7684\u8d77\u59cb\u4f4d\u7f6e\uff0c\u53ca\uff08\u6216\u8005\uff09\u901a\u8fc7\u5728\u4e00\u4e2a\u53ef\u8fed\u4ee3\u5bf9\u8c61\u7684\u5143\u7d20\u524d\u52a0 *\u8fdb\u884c\u4f20\u9012\u3002\u4f8b\u5982 " ,
53+ " print addi(3,5)" ,
54+ " print addi(*(3,5))"
55+ ],
56+ "language" : " python" ,
57+ "outputs" : [
58+ {
59+ "output_type" : " stream" ,
60+ "stream" : " stdout" ,
61+ "text" : [
62+ " 8" ,
63+ " 8" ,
64+ " 8" ,
65+ " 8"
66+ ]
67+ }
68+ ],
69+ "prompt_number" : 5
70+ },
71+ {
72+ "cell_type" : " code" ,
73+ "collapsed" : true ,
74+ "input" : [
75+ " # \u9759\u6001\u51fd\u6570\uff0c\u7c7b\u51fd\u6570\uff0c\u6210\u5458\u51fd\u6570 " ,
76+ " # \u9759\u6001\u51fd\u6570 (@staticmethod): \u5373\u9759\u6001\u65b9\u6cd5 ,\u4e3b\u8981\u5904\u7406\u4e0e\u8fd9\u4e2a\u7c7b\u7684\u903b\u8f91\u5173\u8054 , \u5982\u9a8c\u8bc1\u6570\u636e ;" ,
77+ " # \u7c7b\u51fd\u6570 (@classmethod):\u5373\u7c7b\u65b9\u6cd5 , \u66f4\u5173\u6ce8\u4e8e\u4ece\u7c7b\u4e2d\u8c03\u7528\u65b9\u6cd5 , \u800c\u4e0d\u662f\u5728\u5b9e\u4f8b\u4e2d\u8c03\u7528\u65b9\u6cd5 , \u5982\u6784\u9020\u91cd\u8f7d ;" ,
78+ " # \u6210\u5458\u51fd\u6570 : \u5b9e\u4f8b\u7684\u65b9\u6cd5 , \u53ea\u80fd\u901a\u8fc7\u5b9e\u4f8b\u8fdb\u884c\u8c03\u7528 ;" ,
79+ " class Person:" ,
80+ " grade=1" ,
81+ " def __init__(self,name):" ,
82+ " self.name = name" ,
83+ " " ,
84+ " def sayHi(self):#\u52a0 self\u533a\u522b\u4e8e\u666e\u901a\u51fd\u6570 " ,
85+ " print 'Hello, your name is?',self.name" ,
86+ " " ,
87+ " # \u58f0\u660e\u9759\u6001\uff0c\u53bb\u6389\u5219\u7f16\u8bd1\u62a5\u9519 ;\u8fd8\u6709\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u8bbf\u95ee\u7c7b\u53d8\u91cf\u548c\u5b9e\u4f8b\u53d8\u91cf " ,
88+ " # \u597d\u5904\uff1a\u4e0d\u9700\u8981\u5b9a\u4e49\u5b9e\u4f8b\u5373\u53ef\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u3002\u53e6\u5916\uff0c\u591a\u4e2a\u5b9e\u4f8b\u5171\u4eab\u6b64\u9759\u6001\u65b9\u6cd5\u3002 " ,
89+ " @staticmethod" ,
90+ " def sayName():#\u4f7f\u7528\u4e86\u9759\u6001\u65b9\u6cd5\uff0c\u5219\u4e0d\u80fd\u518d\u4f7f\u7528 self" ,
91+ " print \" my name is king\" #,grade,#self.name" ,
92+ " " ,
93+ " # \u7c7b\u65b9\u6cd5\uff1a\u4e00\u4e2a\u7c7b\u65b9\u6cd5\u5c31\u53ef\u4ee5\u901a\u8fc7\u7c7b\u6216\u5b83\u7684\u5b9e\u4f8b\u6765\u8c03\u7528\u7684\u65b9\u6cd5 , " ,
94+ " # \u4e0d\u7ba1\u4f60\u662f\u7528\u7c7b\u6765\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5\u8fd8\u662f\u7c7b\u5b9e\u4f8b\u8c03\u7528\u8fd9\u4e2a\u65b9\u6cd5 ,\u8be5\u65b9\u6cd5\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u603b\u662f\u5b9a\u4e49\u8be5\u65b9\u6cd5\u7684\u7c7b\u5bf9\u8c61\u3002 " ,
95+ " @classmethod" ,
96+ " def classMethod(cls):" ,
97+ " print(\" class method\" ) "
98+ ],
99+ "language" : " python" ,
100+ "outputs" : []
101+ },
102+ {
103+ "cell_type" : " code" ,
104+ "collapsed" : false ,
105+ "input" : [
106+ " # \u5185\u5efa\u51fd\u6570\uff1a map, reduce, filter" ,
107+ " # map(function, sequence[, sequence, ...]) -> list" ,
108+ " # \u5c06\u51fd\u6570 function\u4f5c\u7528\u4e8e\u7ed9\u5b9a\u5e8f\u5217\u7684\u6bcf\u4e2a\u5143\u7d20\uff0c\u5e76\u7528\u4e00\u4e2a\u5217\u8868\u6765\u63d0\u4f9b\u8fd4\u56de\u503c " ,
109+ " print map(lambda x: x*2, [1,2,3,4])" ,
110+ " # \u82e5 function\u4e3a None\uff0c function\u8868\u73b0\u4e3a\u8eab\u4efd\u51fd\u6570\uff0c\u8fd4\u56de\u4e00\u4e2a\u542b\u6709\u6bcf\u4e2a\u5e8f\u5217\u4e2d\u5143\u7d20\u96c6\u5408\u7684 n\u4e2a\u5143\u7ec4\u7684\u5217\u8868 " ,
111+ " print map(None,[1,2,3,4], [1,2,3,4,5])" ,
112+ " # reduce(function, sequence[, initial]) -> value" ,
113+ " # function\u4e3a\u4e8c\u5143\u51fd\u6570\uff0c\u5c06 function\u4f5c\u7528\u4e8e sequence\u5e8f\u5217\u7684\u5143\u7d20\uff0c\u6bcf\u6b21\u643a\u5e26\u4e00\u5bf9\uff0c " ,
114+ " # \u8fde\u7eed\u7684\u5c06\u73b0\u6709\u7ed3\u679c\u548c\u4e0b\u4e00\u4e2a\u503c\u4f5c\u7528\u5728\u83b7\u5f97\u7684\u968f\u540e\u7684\u7ed3\u679c\u4e0a\uff0c\u6700\u540e\u51cf\u5c11\u6211\u4eec\u7684\u5e8f\u5217\u4e3a\u4e00\u4e2a\u5355\u4e00\u7684\u8fd4\u56de\u503c " ,
115+ " # \u82e5\u7ed9\u5b9a\u521d\u59cb\u503c initial\uff0c\u5219\u7b2c\u4e00\u4e2a\u6bd4\u8f83\u4f1a\u662f initial\u548c\u7b2c\u4e00\u4e2a\u5e8f\u5217\u5143\u7d20\u800c\u4e0d\u662f\u5e8f\u5217\u7684\u5934\u4e24\u4e2a\u5143\u7d20 " ,
116+ " print reduce(lambda x,y: x+y, [1,2,3,4])" ,
117+ " print reduce(lambda x,y: x+y, [1,2,3,4], 10)" ,
118+ " # filter(function or None, sequence) -> list, tuple, or strin" ,
119+ " # \u8fc7\u6ee4\u5668\u3002\u8c03\u7528\u51fd\u6570 function\u6765\u8fed\u4ee3\u904d\u5386 sequence\u4e2d\u6bcf\u4e2a\u5143\u7d20\uff0c\u8fd4\u56de\u4e00\u4e2a\u4f7f function\u8fd4\u56de\u503c\u4e3a true\u7684\u5143\u7d20\u5217\u8868 " ,
120+ " print filter(lambda x: x%2 == 0, [1,2,3,4,5])"
121+ ],
122+ "language" : " python" ,
123+ "outputs" : [
124+ {
125+ "output_type" : " stream" ,
126+ "stream" : " stdout" ,
127+ "text" : [
128+ " [2, 4, 6, 8]" ,
129+ " [(1, 1), (2, 2), (3, 3), (4, 4), (None, 5)]" ,
130+ " 10" ,
131+ " 20" ,
132+ " [2, 4]"
133+ ]
134+ }
135+ ],
136+ "prompt_number" : 13
137+ },
138+ {
139+ "cell_type" : " code" ,
140+ "collapsed" : false ,
141+ "input" : [
142+ " # \u5185\u5efa\u51fd\u6570\uff1a all, any" ,
143+ " # all(iterable) -> bool" ,
144+ " # \u5982\u679c iterable\u7684\u6240\u6709\u5143\u7d20\u4e0d\u4e3a 0\u3001 ''\u3001 False\u6216\u8005 iterable\u4e3a\u7a7a\uff0c all(iterable)\u8fd4\u56de True\uff0c\u5426\u5219\u8fd4\u56de False\uff1b " ,
145+ " print all([2, 4, 6, 8])" ,
146+ " print all([2, 4, 6, 8,0])" ,
147+ " # any(iterable) -> bool" ,
148+ " # \u5982\u679c iterable\u7684\u4efb\u4f55\u4e00\u4e2a\u5143\u7d20\u4e0d\u4e3a 0\u3001 ''\u3001 False,any(iterable)\u8fd4\u56de True\u3002\u5982\u679c iterable\u4e3a\u7a7a\uff0c\u8fd4\u56de False\u3002 " ,
149+ " print any([2, 4, 6, 8])" ,
150+ " print any([2, 4, 6, 8,0])"
151+ ],
152+ "language" : " python" ,
153+ "outputs" : [
154+ {
155+ "output_type" : " stream" ,
156+ "stream" : " stdout" ,
157+ "text" : [
158+ " True" ,
159+ " False" ,
160+ " True" ,
161+ " True"
162+ ]
163+ }
164+ ],
165+ "prompt_number" : 16
166+ },
167+ {
168+ "cell_type" : " code" ,
169+ "collapsed" : true ,
170+ "input" : [],
171+ "language" : " python" ,
172+ "outputs" : []
173+ }
174+ ]
175+ }
176+ ]
177+ }
0 commit comments