-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
435 lines (230 loc) · 333 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Panner&Emily’s paradise!</title>
<link href="http://paneersblog.github.io/atom.xml" rel="self"/>
<link href="http://paneersblog.github.io/"/>
<updated>2022-08-29T02:26:56.902Z</updated>
<id>http://paneersblog.github.io/</id>
<author>
<name>Paneer & Emily</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>Python入门笔记(11)</title>
<link href="http://paneersblog.github.io/41781.html"/>
<id>http://paneersblog.github.io/41781.html</id>
<published>2022-08-04T12:31:21.000Z</published>
<updated>2022-08-29T02:26:56.902Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><h2 id="序列-amp-索引"><a href="#序列-amp-索引" class="headerlink" title="序列&索引"></a>序列&索引</h2><p>序列是一个用于存储多个值的连续空间,每个值都对应一个整数的编号,称为索引<br>序列结构主要有列表、元组、集合、字典和字符串</p><p>索引有正向递增索引,取值范围为[0,N-1]<br>反向递减索引,取值范围[-1,-N]</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">s=<span class="string">'helloworld'</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">0</span>,<span class="built_in">len</span>(s)):</span><br><span class="line"> <span class="built_in">print</span>(i,s[i]) <span class="comment"># 正向递增索引</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(-<span class="number">10</span>,<span class="number">0</span>):</span><br><span class="line"> <span class="built_in">print</span>(i,s[i]) <span class="comment"># 反向递减索引</span></span><br><span class="line"><span class="comment"># 上述语句会输出字符串s中每一个元素以及其索引,索引在前</span></span><br></pre></td></tr></table></figure><h3 id="序列的相关操作"><a href="#序列的相关操作" class="headerlink" title="序列的相关操作"></a>序列的相关操作</h3><p>使用“+”来实现两个同类型序列的相加操作,不会去除重复元素</p><blockquote><p>序列的类型要求是相同的,但序列中元素的类型可以是不同的</p></blockquote><p>使用数字n乘以一个序列,将生成一个新的序列,新序列中的内容将会被重复n次</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">s=<span class="string">'hello'</span></span><br><span class="line">s1=<span class="string">'world'</span></span><br><span class="line"><span class="built_in">print</span>(s+s1) <span class="comment"># 产生一个新的字符串</span></span><br><span class="line"><span class="comment"># -----------</span></span><br><span class="line">lst=[<span class="number">10</span>,<span class="number">20</span>,<span class="number">30</span>]</span><br><span class="line"><span class="built_in">print</span>(s+lst)</span><br><span class="line"><span class="comment"># 此时会报错“TypeError”,因为序列类型不同,lst序列为列表</span></span><br><span class="line"><span class="comment"># -----------</span></span><br><span class="line"><span class="built_in">print</span>(s*<span class="number">5</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'-'</span>*<span class="number">8</span>) <span class="comment"># 序列相乘</span></span><br></pre></td></tr></table></figure><ul><li>序列的相关操作符与函数</li></ul><table><thead><tr><th align="center">操作符</th><th align="left">描述</th></tr></thead><tbody><tr><td align="center">x in s</td><td align="left">如果x为s中的元素,结果为True,否则为False</td></tr><tr><td align="center">x not in s</td><td align="left">如果x不是s中的元素,结果为True,否则为False</td></tr><tr><td align="center">len(s)</td><td align="left">序列s中元素的个数</td></tr><tr><td align="center">max(s)</td><td align="left">序列s元素中的最大值</td></tr><tr><td align="center">min(s)</td><td align="left">序列s元素中的最小值</td></tr><tr><td align="center">s.index(x)</td><td align="left">序列s中第一次出现元素x的位置</td></tr><tr><td align="center">s.count(x)</td><td align="left">序列s中出现x的总次数</td></tr></tbody></table><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">s=<span class="string">'helloworld'</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'e在hello world中存在吗'</span>,(<span class="string">'e'</span> <span class="keyword">in</span> s)) <span class="comment"># 输出为True</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'e不在hello world中存在吗'</span>,(<span class="string">'e'</span> <span class="keyword">not</span> <span class="keyword">in</span> s)) <span class="comment"># 输出为False</span></span><br></pre></td></tr></table></figure><h2 id="列表"><a href="#列表" class="headerlink" title="列表"></a>列表</h2><ul><li>一系列的按特定顺序排列的元素组成</li><li>Python中内置的可变序列</li><li>使用[]定义列表,元素之间使用逗号分隔</li><li>元素可以是任意的数据类型</li></ul><h3 id="列表的创建"><a href="#列表的创建" class="headerlink" title="列表的创建"></a>列表的创建</h3><ol><li>使用[]直接创建列表</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># List_name=[element1,element2,...elementN]</span></span><br><span class="line">lst=[<span class="string">'hello'</span>,<span class="string">'world'</span>,<span class="number">99.8</span>,<span class="number">100</span>]</span><br></pre></td></tr></table></figure><ol start="2"><li>使用内置方法list()创建列表</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># List_name=list(序列)</span></span><br><span class="line">lst=<span class="built_in">list</span>(<span class="string">'hellloworld'</span>)</span><br><span class="line">lst1=<span class="built_in">list</span>(<span class="built_in">range</span>(<span class="number">1</span>,<span class="number">10</span>,<span class="number">2</span>)) <span class="comment"># 输出1-10(不包含),步长为2的列表</span></span><br></pre></td></tr></table></figure><blockquote><p>列表是序列的一种,对序列可操作的运算符、函数等均能用于列表 </p></blockquote><h3 id="列表的删除"><a href="#列表的删除" class="headerlink" title="列表的删除"></a>列表的删除</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">del</span> List_name</span><br></pre></td></tr></table></figure><h3 id="列表元素的遍历"><a href="#列表元素的遍历" class="headerlink" title="列表元素的遍历"></a>列表元素的遍历</h3><ol><li>使用遍历循环for</li><li>遍历循环for与range()函数和len()函数组合遍历</li><li>遍历循环for与enumerate()函数组合遍历元素和索引</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">lst=[<span class="string">'hello'</span>,<span class="string">'world'</span>,<span class="string">'python'</span>,<span class="string">'html'</span>]</span><br><span class="line"><span class="keyword">for</span> item <span class="keyword">in</span> lst:</span><br><span class="line"> <span class="built_in">print</span>(item)</span><br><span class="line"><span class="comment"># ----------</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="built_in">len</span>(lst)):</span><br><span class="line"> <span class="built_in">print</span>(i,<span class="string">'-->'</span>,lst[i])</span><br><span class="line"><span class="comment"># ----------</span></span><br><span class="line"><span class="keyword">for</span> index,item <span class="keyword">in</span> <span class="built_in">enumerate</span>(lst): <span class="comment"># 序号从0开始</span></span><br><span class="line"> <span class="built_in">print</span>(index,item)</span><br><span class="line"><span class="comment"># -----</span></span><br><span class="line"><span class="keyword">for</span> index,item <span class="keyword">in</span> <span class="built_in">enumerate</span>(lst,<span class="number">10</span>): <span class="comment"># 序号从10开始</span></span><br><span class="line"> <span class="built_in">print</span>(index,item)</span><br><span class="line"><span class="comment"># index:用于保存元素的索引(序号)</span></span><br><span class="line"><span class="comment"># item:用于保存获取到的元素值</span></span><br></pre></td></tr></table></figure><h3 id="列表的相关操作方法"><a href="#列表的相关操作方法" class="headerlink" title="列表的相关操作方法"></a>列表的相关操作方法</h3><table><thead><tr><th align="center">方法</th><th align="left">描述</th></tr></thead><tbody><tr><td align="center">lst.append(x)</td><td align="left">在列表lst最后增加一个元素</td></tr><tr><td align="center">lst.insert(index,x)</td><td align="left">在列表lst中第index位置增加一个元素</td></tr><tr><td align="center">lst.clear()</td><td align="left">清除列表lst中所有元素</td></tr><tr><td align="center">lst.pop(index)</td><td align="left">将列表lst中第index位置的元素取出,并从列表中将其删除</td></tr><tr><td align="center">lst.remove(x)</td><td align="left">将列表lst中出现的第一个元素x删除</td></tr><tr><td align="center">lst.reverse(x)</td><td align="left">将列表lst中的元素反转</td></tr><tr><td align="center">lst.copy()</td><td align="left">拷贝列表lst中的所有元素,生成一个新的列表</td></tr></tbody></table><h3 id="列表排序"><a href="#列表排序" class="headerlink" title="列表排序"></a>列表排序</h3><ol><li>列表对象的sort()方法<br>对原列表中的元素进行排序,排序之后原列表中元素的顺序将发生改变</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">lst.sort(key=<span class="literal">None</span>,reverse=<span class="literal">False</span>)</span><br><span class="line"><span class="comment"># reverse的值为False时为升序排序,为True时降序排序,默认值为False</span></span><br><span class="line"><span class="comment"># key的值为'str.lower'时,对英文字母排序时将忽略大小写(默认排序时按照字母对应的ASC II进行排序)。</span></span><br></pre></td></tr></table></figure><ol start="2"><li>内置的sorted()函数<br>使用sorted()函数排序后,原列表不变,排序后产生一个新的列表对象</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># sorted(iterable,key=None,reverse=False)</span></span><br><span class="line">lst=[Cat,apple,Orange,banana]</span><br><span class="line"><span class="built_in">sorted</span>(lst,key=<span class="built_in">str</span>.lower)</span><br><span class="line"><span class="comment"># 此时为忽略大小写的排序</span></span><br></pre></td></tr></table></figure><h3 id="列表生成式"><a href="#列表生成式" class="headerlink" title="列表生成式"></a>列表生成式</h3><ul><li>生成指定范围的数值列表</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># lst=[expression for item in range]</span></span><br><span class="line">lst=[item <span class="keyword">for</span> item <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">11</span>)]</span><br><span class="line"><span class="comment"># 得到[1,2,3,4,5,6,7,8,9,10]</span></span><br><span class="line">lst=[item*item <span class="keyword">for</span> item <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">11</span>)]</span><br><span class="line"><span class="comment"># 得到[1,4,9,16,25,36,49,64,81,100]</span></span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line">lst=[random.randint(<span class="number">1</span>,<span class="number">100</span>) <span class="keyword">for</span> _ <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">10</span>)]</span><br><span class="line"><span class="comment"># 此时会得到10个1-100之间的随机数,for in在这里的作用仅仅是确定次数</span></span><br></pre></td></tr></table></figure><ul><li>从列表中选择符合条件的元素组成新的列表</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># lst=[expression for item in 列表 if condition]</span></span><br><span class="line">lst=[i <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">10</span>) <span class="keyword">if</span> i%<span class="number">2</span>==<span class="number">0</span>]</span><br><span class="line"><span class="comment"># 此时会得到列表[0,2,4,6,8]</span></span><br></pre></td></tr></table></figure><h3 id="二维列表"><a href="#二维列表" class="headerlink" title="二维列表"></a>二维列表</h3><p>二维列表也称为表格数据,由行和列组成</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 建立一个二维列表</span></span><br><span class="line">lst=[</span><br><span class="line"> [<span class="string">'city'</span>,<span class="string">'环比'</span>,<span class="string">'同比'</span>],</span><br><span class="line"> [<span class="string">'北京'</span>,<span class="number">101</span>,<span class="number">103</span>],</span><br><span class="line"> [<span class="string">'上海'</span>,<span class="number">101</span>,<span class="number">103</span>],</span><br><span class="line"> [<span class="string">'深圳'</span>,<span class="number">101</span>,<span class="number">103</span>]</span><br><span class="line">]</span><br><span class="line"><span class="keyword">for</span> row <span class="keyword">in</span> lst:</span><br><span class="line"> <span class="keyword">for</span> item <span class="keyword">in</span> row:</span><br><span class="line"> <span class="built_in">print</span>(item,end=<span class="string">'\t'</span>)</span><br><span class="line"> <span class="built_in">print</span>()</span><br><span class="line"><span class="comment"># 外层循环为行,内层循环为列</span></span><br></pre></td></tr></table></figure><p>列表生成一个四行五列的列表:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">lst=[(j <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">5</span>)) <span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">4</span>)]</span><br><span class="line"><span class="built_in">print</span>(lst)</span><br></pre></td></tr></table></figure><h2 id="组合数据类型——元组"><a href="#组合数据类型——元组" class="headerlink" title="组合数据类型——元组"></a>组合数据类型——元组</h2><p>元组: </p><ul><li>一系列按特定顺序排列的元素组成</li><li>Python中的不可变序列</li><li>使用()定义,元素之间使用逗号分隔</li><li>元组中的数据可以是任意数据类型</li></ul><p>元组的创建:</p><ul><li>使用()直接创建元组</li><li>使用内置函数tuple()创建元组</li></ul><p>元组的删除:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">del</span> 元组名</span><br></pre></td></tr></table></figure><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 使用()创建元组</span></span><br><span class="line">t=(<span class="string">'hello'</span>,[<span class="number">10</span>,<span class="number">20</span>,<span class="number">30</span>],<span class="string">'python'</span>,<span class="string">'world'</span>)</span><br><span class="line"><span class="built_in">print</span>(t)</span><br><span class="line"><span class="comment"># 此时会得到:('hello',[10,20,30],'python','world')</span></span><br><span class="line"><span class="comment"># ------------</span></span><br><span class="line"><span class="comment"># 使用tuple()创建元组</span></span><br><span class="line">t=<span class="built_in">tuple</span>(<span class="string">'helloworld'</span>)</span><br><span class="line"><span class="built_in">print</span>(t)</span><br><span class="line"><span class="comment"># 此时会得到:('h','e','l','l','o','w','o','r','l','d')</span></span><br><span class="line"><span class="comment"># ------------</span></span><br><span class="line">t=<span class="built_in">tuple</span>([<span class="number">10</span>,<span class="number">20</span>,<span class="number">30</span>,<span class="number">40</span>])</span><br><span class="line"><span class="built_in">print</span>(t)</span><br><span class="line"><span class="comment"># 此时会得到:(10,20,30,40)</span></span><br><span class="line"><span class="comment"># ------------</span></span><br><span class="line">t=<span class="built_in">tuple</span>(<span class="built_in">range</span>(<span class="number">1</span>,<span class="number">10</span>))</span><br><span class="line"><span class="built_in">print</span>(t)</span><br><span class="line"><span class="comment"># 此时会得到:(1,2,3,4,5,6,7,8,9)</span></span><br><span class="line"><span class="comment"># ************</span></span><br><span class="line"><span class="comment"># 元组也是一种序列,也可以使用序列的相关操作。如:</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'10在元组中是否存在:'</span>,(<span class="number">10</span> <span class="keyword">in</span> t))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'10在元组中不存在:'</span>,(<span class="number">10</span> <span class="keyword">not</span> <span class="keyword">in</span> t))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'max:'</span>,<span class="built_in">max</span>(t))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'min:'</span>,<span class="built_in">min</span>(t))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'len:'</span>,<span class="built_in">len</span>(t))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'t.index:'</span>,t.index(<span class="number">1</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'t.count:'</span>,t.count(<span class="number">3</span>))</span><br><span class="line"><span class="comment"># ************</span></span><br><span class="line"><span class="comment"># 元组中只有一个元素时,应加上“,”</span></span><br><span class="line">x=(<span class="number">10</span>)</span><br><span class="line">y=(<span class="number">10</span>,)</span><br><span class="line"><span class="built_in">print</span>(x,<span class="built_in">type</span>(x))</span><br><span class="line"><span class="built_in">print</span>(y,<span class="built_in">type</span>(y))</span><br><span class="line"><span class="comment"># 会得到:</span></span><br><span class="line"><span class="comment"># 10 <class 'int'></span></span><br><span class="line"><span class="comment"># (10,) <class 'tuple'></span></span><br></pre></td></tr></table></figure><h2 id="元组与列表的区别"><a href="#元组与列表的区别" class="headerlink" title="元组与列表的区别"></a>元组与列表的区别</h2><table><thead><tr><th align="left">列表</th><th align="left">元组</th></tr></thead><tbody><tr><td align="left">可变序列</td><td align="left">不可变序列</td></tr><tr><td align="left">append(),inset(),remove(),pop()等方法实现添加和删除列表元素</td><td align="left">没有这几个方法,无法实现添加删除和修改元素等操作</td></tr><tr><td align="left">支持切片访问和修改列表中的元素</td><td align="left">支持切片访问元素,不支持修改操作</td></tr><tr><td align="left">访问和处理速度慢</td><td align="left">访问处理速度快</td></tr><tr><td align="left">不能作为字典的键</td><td align="left">可以作为字典的键</td></tr></tbody></table><h2 id="组合数据类型——字典"><a href="#组合数据类型——字典" class="headerlink" title="组合数据类型——字典"></a>组合数据类型——字典</h2><ul><li><p>键对值<br>根据一个信息查找另一个信息的方式构成了“键对值”,它对表示索引用的的键和对应的值构成的成对关系</p></li><li><p>字典的特征</p><ul><li>通过键从字典中获取指定的项,但不能通过索引来获取</li><li>字典是无序的,也被称为hash表(散列表)</li><li>是Python中的可变序列</li><li>字典中的键必须唯一,如果出现两次,后出现的将覆盖先出现的</li><li>字典中的键要求是不可变序列</li></ul></li><li><p>字典的创建</p></li></ul><ol><li>使用{}直接创建字典</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">d={key1:value1,key2:value2......}</span><br></pre></td></tr></table></figure><ol start="2"><li>使用内置函数dict()创建字典</li></ol><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 通过映射函数创建字典</span></span><br><span class="line"><span class="built_in">zip</span>(lst1,lst2)</span><br><span class="line"><span class="comment"># 通过给定关键字创建字典</span></span><br><span class="line"><span class="built_in">dict</span>(key1=value1,key2=value2......)</span><br></pre></td></tr></table></figure><p>demo</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 直接使用{}创建</span></span><br><span class="line">d={<span class="number">10</span>:<span class="string">'cat'</span>,<span class="number">20</span>:<span class="string">'dog'</span>,<span class="number">30</span>:<span class="string">'pet'</span>,<span class="number">20</span>:<span class="string">'zoo'</span>}</span><br><span class="line"><span class="built_in">print</span>(d)</span><br><span class="line"><span class="comment"># 输出结果:{10:'cat',20:'zoo',30:'pet'}</span></span><br><span class="line"><span class="comment"># -----------</span></span><br><span class="line"><span class="comment"># 使用内置函数dict()创建</span></span><br><span class="line"><span class="comment"># zip函数</span></span><br><span class="line">lst1=[<span class="number">10</span>,<span class="number">20</span>,<span class="number">30</span>,<span class="number">40</span>]</span><br><span class="line">lst2=[<span class="string">'cat'</span>,<span class="string">'dog'</span>,<span class="string">'car'</span>,<span class="string">'zoo'</span>]</span><br><span class="line">zipobj=<span class="built_in">zip</span>(lst1,lst2)</span><br><span class="line"><span class="built_in">print</span>(zipobj) </span><br><span class="line"><span class="comment"># 此时会得到一个zipobject,我理解为一个压缩包</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">list</span>(zipobj)) </span><br><span class="line"><span class="comment"># 将zipobj转化为列表去查看,just like 解压</span></span><br><span class="line"><span class="comment"># 会得到[(10,'cat'),(20,'dog'),(30,'car'),(40,'zoo')]</span></span><br><span class="line">d=<span class="built_in">dict</span>(zipobj)</span><br><span class="line"><span class="built_in">print</span>(d)</span><br><span class="line"><span class="comment"># 此时会输出字典d</span></span><br><span class="line"><span class="comment"># -----------</span></span><br><span class="line"><span class="comment"># 使用参数创建字典</span></span><br><span class="line">d=<span class="built_in">dict</span>(cat=<span class="number">10</span>,dog=<span class="number">20</span>) <span class="comment"># 参数相当于变量,变量名不加引号</span></span><br><span class="line"><span class="built_in">print</span>(d)</span><br><span class="line"><span class="comment"># 输出结果:{'cat':10,'dog':20}</span></span><br><span class="line"><span class="comment"># ***********</span></span><br><span class="line"><span class="comment"># 元组可做键</span></span><br><span class="line">t=(<span class="number">10</span>,<span class="number">20</span>,<span class="number">30</span>)</span><br><span class="line"><span class="built_in">print</span>({t:<span class="number">10</span>})</span><br><span class="line"><span class="comment"># 输出结果为:{(10,20,30):10}</span></span><br><span class="line"><span class="comment"># 列表不可做键</span></span><br><span class="line">lst=[<span class="number">10</span>,<span class="number">20</span>,<span class="number">30</span>]</span><br><span class="line"><span class="built_in">print</span>({lst:<span class="number">10</span>})</span><br><span class="line"><span class="comment"># TypeError</span></span><br><span class="line"><span class="comment"># ***********</span></span><br><span class="line"><span class="comment"># 字典属于序列类型,可以使用序列的相关操作</span></span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Pyhton入门笔记(十)</title>
<link href="http://paneersblog.github.io/34793.html"/>
<id>http://paneersblog.github.io/34793.html</id>
<published>2022-08-03T07:08:20.000Z</published>
<updated>2022-08-03T08:17:26.567Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><h2 id="项目案例"><a href="#项目案例" class="headerlink" title="项目案例"></a>项目案例</h2><p><strong>题目</strong>:<br>实现一个人机对战的恶小游戏–〉剪刀、石头、布<br><strong>需求</strong>:</p><ul><li>分析人物角色<ul><li>玩家,玩家出拳:1==石头 2==剪刀 3==布</li><li>电脑,电脑角色出拳,random.randint(1,3)</li></ul></li><li>程序处理<ul><li>使用多重if判断玩家与电脑角色输赢情况</li><li>使用while无限循环实现多局对战</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># -------</span></span><br><span class="line"><span class="keyword">import</span> random</span><br><span class="line"><span class="comment"># -------</span></span><br><span class="line">player_score=<span class="number">0</span></span><br><span class="line">computer_score=<span class="number">0</span></span><br><span class="line"><span class="comment"># -------</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'''</span></span><br><span class="line"><span class="string">* * * * * * * * * * * * * * * * * * * * * * * *</span></span><br><span class="line"><span class="string">* * * * * * * * 欢迎试玩剪刀石头布 * * * * * * * *</span></span><br><span class="line"><span class="string">* * * * * * * * * * * * * * * * * * * * * * * *</span></span><br><span class="line"><span class="string">'''</span>)</span><br><span class="line">player_name=<span class="built_in">input</span>(<span class="string">'请输入玩家姓名:'</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'1.貂蝉 2.曹操 3.诸葛亮'</span>)</span><br><span class="line">choice=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请选择电脑角色:'</span>))</span><br><span class="line"><span class="keyword">if</span> choice==<span class="number">1</span>:</span><br><span class="line"> computer_name=<span class="string">'貂蝉'</span></span><br><span class="line"><span class="keyword">elif</span> choice==<span class="number">2</span>:</span><br><span class="line"> computer_name=<span class="string">'曹操'</span></span><br><span class="line"><span class="keyword">elif</span> choice==<span class="number">3</span>:</span><br><span class="line"> computer_name=<span class="string">'诸葛亮'</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> computer_name=<span class="string">'佚名'</span></span><br><span class="line"><span class="built_in">print</span>(player_name,<span class="string">'VS'</span>,computer_name)</span><br><span class="line"><span class="keyword">while</span> <span class="literal">True</span>:</span><br><span class="line"> <span class="comment"># 玩家出拳</span></span><br><span class="line"> player_fist=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'------请出拳: 1.石头 2.剪刀 3.布------\n'</span>))</span><br><span class="line"> <span class="keyword">if</span> player_fist==<span class="number">1</span>:</span><br><span class="line"> <span class="built_in">print</span>(player_name,<span class="string">'出拳:石头'</span>)</span><br><span class="line"> <span class="keyword">elif</span> player_fist==<span class="number">2</span>:</span><br><span class="line"> <span class="built_in">print</span>(player_name,<span class="string">'出拳:剪刀'</span>)</span><br><span class="line"> <span class="keyword">elif</span> player_fist==<span class="number">3</span>:</span><br><span class="line"> <span class="built_in">print</span>(player_name,<span class="string">'出拳:布'</span>)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(player_name,<span class="string">'出拳:石头'</span>)</span><br><span class="line"> player_fist==<span class="number">1</span></span><br><span class="line"> <span class="comment"># 电脑出拳</span></span><br><span class="line"> computer_fist=random.randint(<span class="number">1</span>,<span class="number">3</span>)</span><br><span class="line"> <span class="keyword">if</span> computer_fist==<span class="number">1</span>:</span><br><span class="line"> <span class="built_in">print</span>(computer_name,<span class="string">'出拳:石头'</span>)</span><br><span class="line"> <span class="keyword">elif</span> computer_fist==<span class="number">2</span>:</span><br><span class="line"> <span class="built_in">print</span>(computer_name,<span class="string">'出拳:剪刀'</span>)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(computer_name,<span class="string">'出拳:布'</span>)</span><br><span class="line"> <span class="keyword">if</span> player_fist==computer_fist:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'平局'</span>)</span><br><span class="line"> <span class="keyword">elif</span> (player_fist==<span class="number">1</span> <span class="keyword">and</span> computer_fist==<span class="number">2</span>) <span class="keyword">or</span> (player_fist==<span class="number">2</span> <span class="keyword">and</span> computer_fist==<span class="number">3</span>) <span class="keyword">or</span> (player_fist==<span class="number">3</span> <span class="keyword">and</span> computer_fist==<span class="number">1</span>):</span><br><span class="line"> <span class="built_in">print</span>(player_name,<span class="string">'获胜'</span>)</span><br><span class="line"> player_score+=<span class="number">1</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(computer_name,<span class="string">'获胜'</span>)</span><br><span class="line"> computer_score+=<span class="number">1</span></span><br><span class="line"> answer=<span class="built_in">input</span>(<span class="string">'再来一句吗?[y/n]'</span>)</span><br><span class="line"> <span class="keyword">if</span> answer!=<span class="string">'y'</span>:</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'---------------'</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'游戏结束'</span>)</span><br><span class="line"><span class="built_in">print</span>(player_name,<span class="string">':'</span>,player_score)</span><br><span class="line"><span class="built_in">print</span>(computer_name,<span class="string">':'</span>,computer_score)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'---------------'</span>)</span><br><span class="line"><span class="keyword">if</span> player_score>computer_score:</span><br><span class="line"> <span class="built_in">print</span>(player_name,<span class="string">'大获全胜'</span>)</span><br><span class="line"><span class="keyword">elif</span> player_score<computer_score:</span><br><span class="line"> <span class="built_in">print</span>(computer_name,<span class="string">'大获全胜'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'平局'</span>)</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Python入门笔记(九)</title>
<link href="http://paneersblog.github.io/21165.html"/>
<id>http://paneersblog.github.io/21165.html</id>
<published>2022-07-23T13:30:18.000Z</published>
<updated>2022-07-24T12:11:38.858Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><h2 id="实战练习"><a href="#实战练习" class="headerlink" title="实战练习"></a>实战练习</h2><ul><li><strong>题目1</strong>:输入一个年份,判断是否为闰年</li><li>需求:从键盘获取一个四位的整数年份,判断是否为闰年。</li><li>判断条件为:能被4整除但不能被100整除,或者能被400整除</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">year=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入需要判断的年份:'</span>))</span><br><span class="line"><span class="keyword">if</span> (year%<span class="number">4</span>==<span class="number">0</span> <span class="keyword">and</span> year%<span class="number">100</span>!=<span class="number">0</span>)<span class="keyword">or</span>(year%<span class="number">400</span>==<span class="number">0</span>):</span><br><span class="line"> <span class="built_in">print</span>(year,<span class="string">'是闰年'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(year,<span class="string">'是平年'</span>)</span><br></pre></td></tr></table></figure><ul><li><strong>题目2</strong>:模拟10086的查询功能</li><li>需求:输入1,显示当前余额;输入2,显示当前剩余流量,单位为G;输入3,显示当前的剩余通话,单位为分钟;输入0,退出自助查询系统</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">answer=<span class="string">'y'</span> <span class="comment"># 初始化变量</span></span><br><span class="line"><span class="keyword">while</span> answer==<span class="string">'y'</span>: <span class="comment"># 条件判断</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'-----欢迎使用10086自助查询系统-----'</span>)</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'1.显示当前余额;\n2.显示当前剩余流量;\n3.显示当前的剩余通话;\n0.退出自助查询系统'</span>)</span><br><span class="line"> choice=<span class="built_in">input</span>(<span class="string">'请输入序号来选择对应查询功能'</span>)</span><br><span class="line"> <span class="keyword">if</span> choice==<span class="string">'1'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'当前话费余额为 100元'</span>)</span><br><span class="line"> <span class="keyword">elif</span> choice==<span class="string">'2'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'当前剩余流量为 128GB'</span>)</span><br><span class="line"> <span class="keyword">elif</span> choice==<span class="string">'3'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'当前剩余通话为 500分钟'</span>)</span><br><span class="line"> <span class="keyword">elif</span> choice==<span class="string">'0'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'系统退出,感谢您的使用'</span>)</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' 您输入的数字无效,请检查后重新输入'</span>) </span><br><span class="line"> answer=<span class="built_in">input</span>(<span class="string">'您是否还需要继续查询?[y/n]'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'系统退出,感谢您的使用'</span>)</span><br></pre></td></tr></table></figure><ul><li><strong>题目3</strong>:使用嵌套循环输出九九乘法表</li><li>需求:直角三角形形状的九九乘法表</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">10</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,i+<span class="number">1</span>):</span><br><span class="line"> <span class="built_in">print</span>(<span class="built_in">str</span>(j)+<span class="string">'*'</span>+<span class="built_in">str</span>(i)+<span class="string">'='</span>+<span class="built_in">str</span>(i*j),end=<span class="string">'\t'</span>)</span><br><span class="line"> <span class="built_in">print</span>()</span><br></pre></td></tr></table></figure><h2 id="程序流程图"><a href="#程序流程图" class="headerlink" title="程序流程图"></a>程序流程图</h2><p>用一系列图形、流程线和文字说明描述程序的基本操作和控制流程,它是程序分析和过程描述的最基本方式。<br>流程图的七种基本元素如下图:</p><p><a href="/404"><img src="/21165/%E6%B5%81%E7%A8%8B%E5%9B%BE.png" class="" title="流程图的七种基本元素"></a> </p>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Python入门笔记(八)</title>
<link href="http://paneersblog.github.io/3827.html"/>
<id>http://paneersblog.github.io/3827.html</id>
<published>2022-07-23T08:43:13.000Z</published>
<updated>2022-07-24T14:00:17.258Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><h2 id="程序跳转语句"><a href="#程序跳转语句" class="headerlink" title="程序跳转语句"></a>程序跳转语句</h2><h3 id="break跳转语句"><a href="#break跳转语句" class="headerlink" title="break跳转语句"></a>break跳转语句</h3><p>只能在循环结构中使用,通常与if一起搭配使用</p><ul><li>whlie循环语法结构:</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">whlie 表达式<span class="number">1</span>:</span><br><span class="line"> 执行代码</span><br><span class="line"> <span class="keyword">if</span> 表达式<span class="number">2</span>:</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"><span class="comment"># 表达式1为False时退出循环 OR 表达式2为true时循环退出</span></span><br></pre></td></tr></table></figure><p>案例:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1-10内累加和大于20时的数</span></span><br><span class="line">s=<span class="number">0</span> <span class="comment"># 存储累加和</span></span><br><span class="line">i=<span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> i<<span class="number">11</span>:</span><br><span class="line"> s+=i</span><br><span class="line"> <span class="keyword">if</span> s><span class="number">20</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'累加和大于20的当前数为:'</span>,i)</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"></span><br></pre></td></tr></table></figure><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 模拟登录</span></span><br><span class="line">i=<span class="number">0</span></span><br><span class="line"><span class="keyword">while</span> i<<span class="number">3</span>:</span><br><span class="line"> user_name=<span class="built_in">input</span>(<span class="string">'请输入用户名:'</span>)</span><br><span class="line"> pwd=<span class="built_in">input</span>(<span class="string">'请输入密码:'</span>)</span><br><span class="line"> <span class="keyword">if</span> user_name==<span class="string">'Paneer'</span> <span class="keyword">and</span> pwd==<span class="string">'password'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'正在登录中...'</span>)</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">if</span> i<<span class="number">2</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'账号或密码错误,您还有'</span>,<span class="number">2</span>-i,<span class="string">'次机会'</span>)</span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'连续错误三次,请稍后再试'</span>)</span><br></pre></td></tr></table></figure><ul><li>for循环语法结构</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> 循环变量 <span class="keyword">in</span> 遍历对象:</span><br><span class="line"> 执行代码</span><br><span class="line"> <span class="keyword">if</span> 表达式:</span><br><span class="line"> <span class="keyword">break</span></span><br></pre></td></tr></table></figure><p>案例:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">3</span>):</span><br><span class="line"> user_name=<span class="built_in">input</span>(<span class="string">'请输入用户名:'</span>)</span><br><span class="line"> pwd=<span class="built_in">input</span>(<span class="string">'请输入密码:'</span>)</span><br><span class="line"> <span class="keyword">if</span> user_name==<span class="string">'Paneer'</span> <span class="keyword">and</span> pwd==<span class="string">'password'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'正在登录中...'</span>)</span><br><span class="line"> <span class="keyword">break</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">if</span> i<<span class="number">2</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'账号或密码错误,您还有'</span>,<span class="number">2</span>-i,<span class="string">'次机会'</span>)</span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'连续错误三次,请稍后再试'</span>)</span><br></pre></td></tr></table></figure><h3 id="continue跳转语句"><a href="#continue跳转语句" class="headerlink" title="continue跳转语句"></a>continue跳转语句</h3><p>break会跳出循环,而continue只会结束本次循环</p><ul><li>语法结构</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> 表达式<span class="number">1</span>:</span><br><span class="line"> 执行代码</span><br><span class="line"> <span class="keyword">if</span> 表达式<span class="number">2</span>:</span><br><span class="line"> <span class="keyword">continue</span></span><br></pre></td></tr></table></figure><p>案例:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 计算1-100内的偶数和</span></span><br><span class="line">s=<span class="number">0</span></span><br><span class="line">i=<span class="number">1</span></span><br><span class="line"><span class="keyword">while</span> i<=<span class="number">100</span>:</span><br><span class="line"> <span class="keyword">if</span> i%<span class="number">2</span>==<span class="number">1</span>:</span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"> <span class="keyword">continue</span></span><br><span class="line"> s+=i</span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'1-100内的偶数和为:'</span>,s)</span><br></pre></td></tr></table></figure><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 计算1-100内的偶数和</span></span><br><span class="line">s=<span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">101</span>):</span><br><span class="line"> <span class="keyword">if</span> i%<span class="number">2</span>==<span class="number">1</span>:</span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"> <span class="keyword">continue</span></span><br><span class="line"> s+=i</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'1-100内的偶数和为:'</span>,s)</span><br></pre></td></tr></table></figure><h2 id="空语句pass"><a href="#空语句pass" class="headerlink" title="空语句pass"></a>空语句pass</h2><ul><li>不做任何事情,只起到占位符作用,使用语法结构完整,不报错</li><li>一般可用在 if、for、while、函数的定义、类的定义中</li></ul><hr><ul><li><strong>语法结构:</strong></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> 表达式:</span><br><span class="line"> <span class="keyword">pass</span></span><br><span class="line"><span class="comment"># --------------------</span></span><br><span class="line"><span class="keyword">while</span> 表达式:</span><br><span class="line"> <span class="keyword">pass</span></span><br><span class="line"><span class="comment"># --------------------</span></span><br><span class="line"><span class="keyword">for</span> 循环变量 <span class="keyword">in</span> 遍历对象:</span><br><span class="line"> <span class="keyword">pass</span></span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Python入门笔记(七)</title>
<link href="http://paneersblog.github.io/47766.html"/>
<id>http://paneersblog.github.io/47766.html</id>
<published>2022-07-22T06:20:09.000Z</published>
<updated>2022-07-23T01:30:57.713Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><h3 id="循环结构"><a href="#循环结构" class="headerlink" title="循环结构"></a>循环结构</h3><ul><li>嵌套循环</li></ul><p>在一个循环结构中嵌套另一个完整的循环结构</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ----------------------------</span></span><br><span class="line"><span class="keyword">while</span> 表达式<span class="number">1</span>:</span><br><span class="line"> <span class="keyword">while</span> 表达式<span class="number">2</span>:</span><br><span class="line"> 语句块<span class="number">2</span></span><br><span class="line"><span class="comment"># ----------------------------</span></span><br><span class="line"><span class="keyword">for</span> 循环变量<span class="number">1</span> <span class="keyword">in</span> 遍历对象<span class="number">1</span>:</span><br><span class="line"> <span class="keyword">for</span> 循环变量<span class="number">2</span> <span class="keyword">in</span> 遍历对象<span class="number">2</span>:</span><br><span class="line"> 语句块<span class="number">2</span></span><br><span class="line"><span class="comment"># ----------------------------</span></span><br></pre></td></tr></table></figure><p>生成三行四列*号:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">4</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">5</span>):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="built_in">print</span>() <span class="comment">#换行</span></span><br></pre></td></tr></table></figure><p>生成直角三角形:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">6</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,i+<span class="number">1</span>):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="built_in">print</span>() <span class="comment">#换行</span></span><br></pre></td></tr></table></figure><p>生成倒直角三角形:</p><blockquote><p>*****<br>****<br>***<br>**<br>*</p></blockquote><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">6</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">7</span>-i): <span class="comment"># 1-->5 2-->4 ...</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="built_in">print</span>() <span class="comment">#换行</span></span><br></pre></td></tr></table></figure><p>生成等腰三角形:<br>&&&&*<br>&&&***<br>&&*****<br>&*******<br>********\ *</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">6</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">6</span>-i):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' '</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">2</span>*i):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>)</span><br><span class="line"> <span class="built_in">print</span>() <span class="comment">#换行</span></span><br></pre></td></tr></table></figure><p>生成棱形:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">row=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入棱形的行数:'</span>))</span><br><span class="line"><span class="keyword">while</span> row%<span class="number">2</span>==<span class="number">0</span>:</span><br><span class="line"> <span class="built_in">print</span>:(<span class="string">'请重新输入棱形的行数,限奇数:'</span>)</span><br><span class="line"> row=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入棱形的行数:'</span>))</span><br><span class="line"><span class="comment"># ---先生成上半部分---</span></span><br><span class="line">top_row=(row+<span class="number">1</span>)//<span class="number">2</span> <span class="comment"># 上半部分行数</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,top_row+<span class="number">1</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,top_row+<span class="number">1</span>-i):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' '</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">2</span>*i):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>)</span><br><span class="line"> <span class="built_in">print</span>() <span class="comment">#换行</span></span><br><span class="line"><span class="comment"># ---在生成下半部分---</span></span><br><span class="line">bottom_row=row//<span class="number">2</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,bottom_row+<span class="number">1</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,i+<span class="number">1</span>):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' '</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">2</span>*bottom_row-<span class="number">2</span>*i+<span class="number">2</span>):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>)</span><br><span class="line"> <span class="built_in">print</span>()</span><br></pre></td></tr></table></figure><p>生成空心棱形:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">row=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入棱形的行数:'</span>))</span><br><span class="line"><span class="keyword">while</span> row%<span class="number">2</span>==<span class="number">0</span>:</span><br><span class="line"> <span class="built_in">print</span>:(<span class="string">'请重新输入棱形的行数,限奇数:'</span>)</span><br><span class="line"> row=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入棱形的行数:'</span>))</span><br><span class="line"><span class="comment"># ---先生成上半部分---</span></span><br><span class="line">top_row=(row+<span class="number">1</span>)//<span class="number">2</span> <span class="comment"># 上半部分行数</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,top_row+<span class="number">1</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,top_row+<span class="number">1</span>-i):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' '</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">2</span>*i):</span><br><span class="line"> <span class="keyword">if</span> k==<span class="number">1</span> <span class="keyword">or</span> k==<span class="number">2</span>*i-<span class="number">1</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' '</span>,end=<span class="string">''</span>)</span><br><span class="line"> <span class="built_in">print</span>() <span class="comment">#换行</span></span><br><span class="line"><span class="comment"># ---在生成下半部分---</span></span><br><span class="line">bottom_row=row//<span class="number">2</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,bottom_row+<span class="number">1</span>):</span><br><span class="line"> <span class="keyword">for</span> j <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,i+<span class="number">1</span>):</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' '</span>,end=<span class="string">''</span>) </span><br><span class="line"> <span class="keyword">for</span> k <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">2</span>*bottom_row-<span class="number">2</span>*i+<span class="number">2</span>):</span><br><span class="line"> <span class="keyword">if</span> k==<span class="number">1</span> <span class="keyword">or</span> k==<span class="number">2</span>*bottom_row-<span class="number">2</span>*i+<span class="number">2</span>-<span class="number">1</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'*'</span>,end=<span class="string">''</span>)</span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">' '</span>,end=<span class="string">''</span>)</span><br><span class="line"> <span class="built_in">print</span>()</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Python入门笔记(六)</title>
<link href="http://paneersblog.github.io/34547.html"/>
<id>http://paneersblog.github.io/34547.html</id>
<published>2022-07-20T09:57:32.000Z</published>
<updated>2022-07-21T03:18:24.600Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><hr><h3 id="逻辑运算符-and与-or运算"><a href="#逻辑运算符-and与-or运算" class="headerlink" title="逻辑运算符 and与 or运算"></a>逻辑运算符 and与 or运算</h3><p>使用 and连接多个选择条件时:</p><ul><li>只有同时满足多个条件才能执行if后面的语句块</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">user_name=<span class="built_in">input</span>(<span class="string">'请输入用户名'</span>)</span><br><span class="line">pwd=<span class="built_in">input</span>(<span class="string">'请输入密码'</span>)</span><br><span class="line"><span class="keyword">if</span> user_name==<span class="string">'root'</span> <span class="keyword">and</span> pwd==<span class="string">'password'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'登录成功'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'用户名或密码不正确'</span>)</span><br></pre></td></tr></table></figure><p>使用 or连接多个选择条件时:</p><ul><li>只要满足多个条件的一个,就可以执行if后的语句块</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">score=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入您的成绩:'</span>))</span><br><span class="line"><span class="keyword">if</span> score<<span class="number">0</span> <span class="keyword">or</span> score><span class="number">100</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'成绩无效'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'您的成绩为'</span>,score)</span><br></pre></td></tr></table></figure><h2 id="循环结构"><a href="#循环结构" class="headerlink" title="循环结构"></a>循环结构</h2><h3 id="遍历循环for"><a href="#遍历循环for" class="headerlink" title="遍历循环for"></a>遍历循环for</h3><ul><li>语法结构</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> 循环变量 <span class="keyword">in</span> 遍历对象:</span><br><span class="line"> 语句块</span><br></pre></td></tr></table></figure><ul><li>遍历对象<ol><li>字符串</li><li>文件</li><li>组合数据类型</li><li>range()函数等</li></ol></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 遍历字符串</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="string">'hello'</span>:</span><br><span class="line"> <span class="built_in">print</span>(i)</span><br><span class="line"><span class="comment"># 输出为:</span></span><br><span class="line"><span class="comment"># h</span></span><br><span class="line"><span class="comment"># e</span></span><br><span class="line"><span class="comment"># l</span></span><br><span class="line"><span class="comment"># l</span></span><br><span class="line"><span class="comment"># o</span></span><br><span class="line"><span class="comment">######</span></span><br></pre></td></tr></table></figure><p>对于<code>range()</code>函数,是一个产生[n,m)的整数序列,包含n不包含m</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">11</span>):</span><br><span class="line"> <span class="built_in">print</span>(i) <span class="comment"># 此时会得到1-10的输出结果</span></span><br><span class="line"> <span class="keyword">if</span> i%<span class="number">2</span>==<span class="number">0</span>:</span><br><span class="line"> <span class="built_in">print</span>(i,<span class="string">'是偶数'</span>) <span class="comment"># 将range函数与if结合,输出偶数。</span></span><br></pre></td></tr></table></figure><p>案例一</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 利用range函数与for循环计算1-10的累加求和</span></span><br><span class="line">s=<span class="number">0</span> <span class="comment"># 设置变量用来存储</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">11</span>):</span><br><span class="line"> s+=i <span class="comment"># 等价于 s=s+i</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'1-10之间的累加和为:'</span>,s)</span><br></pre></td></tr></table></figure><p>案例二</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 计算100-999之间的水仙花数</span></span><br><span class="line"><span class="comment"># ----------------------</span></span><br><span class="line"><span class="comment"># 3*3*3+5*5*5+1*1*1=153</span></span><br><span class="line"><span class="comment"># 形如153这样的数就是水仙花数</span></span><br><span class="line"><span class="comment"># ----------------------</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">100</span>,<span class="number">1000</span>):</span><br><span class="line"> sd=i%<span class="number">10</span> <span class="comment"># 获取个位上的数字</span></span><br><span class="line"> tens=i//<span class="number">10</span>%<span class="number">10</span> <span class="comment"># 获取十位上的数字</span></span><br><span class="line"> hundred=i//<span class="number">100</span> <span class="comment"># 获取百位上的数字</span></span><br><span class="line"> <span class="keyword">if</span> sd**<span class="number">3</span>+tens**<span class="number">3</span>+hundred**<span class="number">3</span>==i:</span><br><span class="line"> <span class="built_in">print</span>(i)</span><br></pre></td></tr></table></figure><h3 id="遍历循环的扩展模式"><a href="#遍历循环的扩展模式" class="headerlink" title="遍历循环的扩展模式"></a>遍历循环的扩展模式</h3><ul><li>语法结构</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> 循环变量 <span class="keyword">in</span> 遍历对:</span><br><span class="line"> 语句块<span class="number">1</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> 语句块<span class="number">2</span></span><br></pre></td></tr></table></figure><blockquote><p>其中else语句只在循环正常结束后才执行<br>通常与break和continue语句一起使用</p></blockquote><p>简单案例如下:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">s=<span class="number">0</span> <span class="comment"># 设置变量用来存储</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> <span class="built_in">range</span>(<span class="number">1</span>,<span class="number">11</span>):</span><br><span class="line"> s+=i <span class="comment"># 等价于 s=s+i</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'1-10之间的累加和为:'</span>,s)</span><br></pre></td></tr></table></figure><p>结果不变,但程序逻辑不同。</p><h3 id="无限循环while"><a href="#无限循环while" class="headerlink" title="无限循环while"></a>无限循环while</h3><ul><li>语法结构</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> 表达式:</span><br><span class="line"> 语句块</span><br></pre></td></tr></table></figure><ul><li>执行流程<ul><li>当表达式的值为true时,执行语句块</li><li>当表达式的值为false时,跳过语句块执行后边的代码</li></ul></li></ul><p>案例一</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">answer=<span class="built_in">input</span>(<span class="string">'今天有课吗?[y/n]'</span>) <span class="comment"># 初始化变量</span></span><br><span class="line"><span class="keyword">while</span> answer==<span class="string">'y'</span>: <span class="comment"># 条件判断</span></span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'好好学习'</span>) <span class="comment"># 语句块</span></span><br><span class="line"> answer=<span class="built_in">input</span>(<span class="string">'今天有课吗?[y/n]'</span>) <span class="comment"># 改变变量</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'玩的开心'</span>) <span class="comment"># 语句块</span></span><br></pre></td></tr></table></figure><p>案例二</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1-100之间的数求和</span></span><br><span class="line"><span class="comment"># ---------------</span></span><br><span class="line">s=<span class="number">0</span> <span class="comment"># 存储累加和</span></span><br><span class="line">i=<span class="number">1</span> <span class="comment"># 初始化变量</span></span><br><span class="line"><span class="keyword">while</span> i<=<span class="number">100</span>:</span><br><span class="line"> s+=i <span class="comment"># s=s+i</span></span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'1-100之间的累加和为'</span>,s)</span><br></pre></td></tr></table></figure><h3 id="无限循环的扩展"><a href="#无限循环的扩展" class="headerlink" title="无限循环的扩展"></a>无限循环的扩展</h3><ul><li>语法结构</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">while</span> 表达式:</span><br><span class="line"> 语句块<span class="number">1</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> 语句块<span class="number">2</span></span><br></pre></td></tr></table></figure><blockquote><p>else语句只在循环结构之后才执行<br>通常与break和continue一起使用</p></blockquote><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1-100之间的数求和</span></span><br><span class="line"><span class="comment"># ---------------</span></span><br><span class="line">s=<span class="number">0</span> <span class="comment"># 存储累加和</span></span><br><span class="line">i=<span class="number">1</span> <span class="comment"># 初始化变量</span></span><br><span class="line"><span class="keyword">while</span> i<=<span class="number">100</span>:</span><br><span class="line"> s+=i <span class="comment"># s=s+i</span></span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'1-100之间的累加和为'</span>,s)</span><br></pre></td></tr></table></figure><h3 id="使用无限循环模拟实现登录"><a href="#使用无限循环模拟实现登录" class="headerlink" title="使用无限循环模拟实现登录"></a>使用无限循环模拟实现登录</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">i=<span class="number">0</span> </span><br><span class="line"><span class="keyword">while</span> i<<span class="number">3</span>:</span><br><span class="line"> user_name=<span class="built_in">input</span>(<span class="string">'请输入用户名:'</span>)</span><br><span class="line"> pwd=<span class="built_in">input</span>(<span class="string">'请输入密码:'</span>)</span><br><span class="line"> <span class="keyword">if</span> user_name==<span class="string">'Paneer'</span> <span class="keyword">and</span> pwd==<span class="string">'password'</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'登录成功'</span>)</span><br><span class="line"> i=<span class="number">8</span></span><br><span class="line"> <span class="keyword">else</span>:</span><br><span class="line"> <span class="keyword">if</span> i<<span class="number">2</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'用户名或密码错误,您还有'</span>,<span class="number">2</span>-i,<span class="string">'次机会'</span>)</span><br><span class="line"> i+=<span class="number">1</span></span><br><span class="line"><span class="keyword">if</span> i==<span class="number">3</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'对不起,账号密码连续错误三次,请稍后再试'</span>)</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Anaconda(一)</title>
<link href="http://paneersblog.github.io/16606.html"/>
<id>http://paneersblog.github.io/16606.html</id>
<published>2022-07-19T10:11:02.000Z</published>
<updated>2022-07-19T11:29:15.092Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>最近朋友在学Python,了解到了anaconda,整理如下。</p><span id="more"></span><h2 id="Anaconda简介"><a href="#Anaconda简介" class="headerlink" title="Anaconda简介"></a>Anaconda简介</h2><p>Anaconda包括Conda、Python以及一大堆安装好的工具包,比如:numpy、pandas等。 </p><p>B站一位UP主“肆十二-”的<a href="https://www.bilibili.com/video/BV15o4y127Rt?spm_id_from=333.999.0.0&vd_source=63d2d1a0d927aa620de5a2c9d0fcc470">视频</a>中,运用了一个比较恰当的比喻:他将Anaconda比作超市,pip比作菜市场,pycharm比作了厨房。<br>通过这位UP的比喻我们可以形象的理解,Anaconda和pip里有我们所需要的库,Anaconda相对pip会更规范一些,但pip的库会更全面一些。Pycharm则是实现我们idea的工具了~</p><p>那么使用Anaconda的意义在哪呢?我结合查阅到的资料,分为以下三点:</p><ol><li>包含conda:conda是一个环境管理器,其功能依靠conda包来实现,该环境管理器与pip类似。<blockquote><p>那有童鞋会问了:我能通过pip装conda包达到conda环境管理器一样的功能吗?答案是不能,conda包的实现离不开conda环境管理器。</p></blockquote></li><li>安装大量工具包:Anaconda会自动安装一个基本的python,该python的版本Anaconda的版本有关。<blockquote><p>换句话说就是安装了anaconda就相当于配置好了Python环境,不需要在额外安装一次Python,也不需要再一个个安装工具包。</p></blockquote></li><li>可以创建使用和管理多个不同的Python版本。<blockquote><p>比如想要新建一个新框架或者使用不同于Anoconda装的基本Python版本,Anoconda就可以实现同时多个python版本的管理</p></blockquote></li></ol><h2 id="Anaconda下载与安装"><a href="#Anaconda下载与安装" class="headerlink" title="Anaconda下载与安装"></a>Anaconda下载与安装</h2><p>Anaconda分为完整版和精简版,完整版有完整的图形界面(导致很臃肿),这里我推荐miniconda。<br><strong>老规矩这里是miniconda的<a href="https://docs.conda.io/en/latest/miniconda.html">下载地址</a></strong><br>安装教程不再赘述,记得选<code>Install for All users</code></p><p>安装完成后可以在cmd或者终端中输入:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda -V</span><br></pre></td></tr></table></figure><p>来查看版本,或者输入:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda env list</span><br></pre></td></tr></table></figure><p>查看目前的环境,理论上只会出现一个base环境,正常显示则证明安装完成。 </p><h2 id="通过Anaconda配置虚拟环境"><a href="#通过Anaconda配置虚拟环境" class="headerlink" title="通过Anaconda配置虚拟环境"></a>通过Anaconda配置虚拟环境</h2><p>前面有说到,Anaconda可以管理不同版本的Python,就是利用不同的虚拟环境来实现的。关于虚拟环境大家可以将其简单理解成一个虚拟机,我是这么理解的并没有深入研究。</p><h3 id="创建虚拟环境"><a href="#创建虚拟环境" class="headerlink" title="创建虚拟环境"></a>创建虚拟环境</h3><p>在命令行中输入:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda create -n py37 python==<span class="number">3</span>.<span class="number">7</span></span><br></pre></td></tr></table></figure><p>这条命令的含义就是创建一个名为py37,python版本为3.7的虚拟环境。<br>安装完成后命令行输入y确认即可。</p><h3 id="激活虚拟环境"><a href="#激活虚拟环境" class="headerlink" title="激活虚拟环境"></a>激活虚拟环境</h3><p>安装全部完成之后,在命令行输入:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda activate py37</span><br></pre></td></tr></table></figure><p>此时会在命令行最前面显示:<code>(py37)</code>,表示此时是在py37虚拟环境中的。 </p><p>然后我们可以通过pip指令来安装程序所需要的包从而正常运行我们的python程序了。</p><h2 id="与Pycharm联动"><a href="#与Pycharm联动" class="headerlink" title="与Pycharm联动"></a>与Pycharm联动</h2><p>前文有说Pycharm好比厨房,相对命令行来说更方便我们进行调试程序代码,那么下文将介绍如何在Pycharm中打开程序。 </p><p>还是老规矩,贴上Pycharm的官网<a href="https://www.jetbrains.com/pycharm/download/">下载地址</a></p><p>安装过程不再多言,找到我们的代码文件夹,直接右键通过Pycharm打开即可。<br>打开之后软件的右下角会显示当前的python环境,点击他选择<code>Add interpreter</code>,然后根据提示添加刚才建立的虚拟环境即可。</p><p>在Pycharm中直接打开终端(terminal),执行</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pip install xx</span><br></pre></td></tr></table></figure><p>来安装程序所需的包即可,包会自动安装在当前的虚拟环境下。</p><h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><p>创建虚拟环境 </p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda create -n py37 python==<span class="number">3</span>.<span class="number">7</span></span><br></pre></td></tr></table></figure><p>激活虚拟环境 </p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conda activate py37</span><br></pre></td></tr></table></figure><p>参考资料:<br><a href="https://blog.csdn.net/ECHOSON/article/details/117220445">1.如何在pycharm中配置anaconda的虚拟环境</a><br><a href="https://blog.csdn.net/wq_ocean_/article/details/103889237?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522165822558916782388098546%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=165822558916782388098546&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~top_positive~default-1-103889237-null-null.185%5Ev2%5Econtrol&utm_term=anaconda&spm=1018.2226.3001.4450">2.史上最全最详细的Anaconda安装教程</a><br><a href="https://www.bilibili.com/video/BV15o4y127Rt?spm_id_from=333.999.0.0&vd_source=63d2d1a0d927aa620de5a2c9d0fcc470">3.Python学习中Anaconda和Pycharm的正确打开方式</a></p>]]></content>
<summary type="html"><p>最近朋友在学Python,了解到了anaconda,整理如下。</p></summary>
<category term="软件学习" scheme="http://paneersblog.github.io/categories/%E8%BD%AF%E4%BB%B6%E5%AD%A6%E4%B9%A0/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>MCNP5入门(一)</title>
<link href="http://paneersblog.github.io/54952.html"/>
<id>http://paneersblog.github.io/54952.html</id>
<published>2022-04-05T07:47:05.000Z</published>
<updated>2022-04-05T10:33:39.117Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>MCNP5入门搬运学习,搬砖永无止境</p><span id="more"></span><h3 id="写在前面"><a href="#写在前面" class="headerlink" title="写在前面"></a>写在前面</h3><p>因为有童鞋要用MCNP做毕业设计,且求助于我(orz我何德何能!)</p><p>我对于MCNP也仅仅是停留在“勉强会用”这一水平,故从<a href="http://hejishult.com/">核技术论坛</a>中搬运学习MCNP5的相关知识,并结合自己的理解,完成了此篇笔记。</p><p>AAAAND,希望大家能给自己的电脑装一个好用的文本编辑器(推荐<a href="https://code.visualstudio.com/">vs code</a>!yyds!)<br>vs code的好处就是它可以装很多的扩展,用来提高文件的可读性(代码高亮之类)。至于怎么安装扩展,可以百度vs code汉化教程,因为汉化就是给软件安装简体中文扩展。</p><img src="/54952/uTools_1649138657812.png" class=""><blockquote><p>注:此笔记中提及的软件等请自行寻找,恕不提供。</p></blockquote><hr><h1 id="MCNP概述"><a href="#MCNP概述" class="headerlink" title="MCNP概述"></a>MCNP概述</h1><h2 id="MCNP文件结构"><a href="#MCNP文件结构" class="headerlink" title="MCNP文件结构"></a>MCNP文件结构</h2><p>MCNP的输入文件名不可以多于七个字符,所以不建议对输入文件增加扩展名;MCNP的输出文件的扩展名为.o;MCNP内部计算过程的记录文件的扩展名为.r。*.r 文件一般用于断点计算,在基于上一次的计算结果继续模拟计算时,MCNP将不会读取输入文件,而只读取.r文件的信息。<br>除了上面三种常用的文件类型,MCNP还有两种不长用的输出文件。这两种文件只有用户通过输入文件要求MCNP输出这些文件时才会得到。其中一个为.w文件,这个文件是我们想通过MCNP输出surface source 的时候才会产生;另外一个为.p文件,这个文件时我们想通过MCNP追踪粒子的输运过程的时候才会得到。</p><p>以上几个文件是常用的用户文件,下面将介绍MCNP程序内部使用的若干文件。</p><ol><li>MCNP5.exe 这是MCNP的应用程序,此程序不能双击打开,只能在DOS(cmd)下运行。</li><li>vise.exe 此程序为绘图程序,可以让user观察我们在输入文件中所建立的计算模型(相对于抽象的珊元曲面卡,能可视化检查真的很不错!)。</li><li>MCNPDate 该目录存放的是MCNP的截面库。</li><li>xs52 该文件说明了各个核素的属性,包括质量,截面库内各种反应类型对应的截面存放的位置等。</li><li>X11.dll dll文件,链接动态数据库,重要性不言而喻。</li></ol><p>为了更好的在dos下运行mcnp,我们可以编写一些bat文件。关于bat语法可以关注我之前的博客,或者csdn等寻找学习。</p><blockquote><p>注,使用bat文件时应确保环境变量已经被添加,环境变量中path中的路径决定能不能运行.cmd</p></blockquote><h2 id="MCNP使用方法"><a href="#MCNP使用方法" class="headerlink" title="MCNP使用方法"></a>MCNP使用方法</h2><p>上文我们说到 xs52 文件很重要,但如果你的MCNP为绿色免安装版本的话,还需要对该文件进行简单的修改才能让MCNP找到截面库。<br>我们用记事本打开xs52,可以看到第一行为datapath=X:\LANL\MCNPDATA\。我们需要正确的修改该路径,例如我将我的 LANL文件夹放在了D盘根目录,此时这里的路径就是:D:\LANL\MCNPDATA\<br>经过上述修改之后,我们就能使用MCNP程序来进行计算了。MCNP进行计算时会占据单个cpu的资源,大家的电脑都是多核的,不用担心MCNP会占用太多资源。若想提高计算效率可以使用mpi并行计算,我尝试过一次但并没有成功orz,大家感兴趣可以自行了解尝试。</p><h2 id="MCNP-输入文件书写方法"><a href="#MCNP-输入文件书写方法" class="headerlink" title="MCNP 输入文件书写方法"></a>MCNP 输入文件书写方法</h2><h3 id="输入文件规范"><a href="#输入文件规范" class="headerlink" title="输入文件规范"></a>输入文件规范</h3><p>MCNP的输入文件在结构上基本上可以分为三块,分别为cell块、surface块和其他内容。块内除了注释外,不得有空行,而两个块之间只能有一个空行。通常情况下,每一行中只能有一个主导性的助记符,这个助记符可以有很多参数和附属的次要助记符。MCNP官方手册中称这样的助记符为卡(card)。每一列不得超过80个字符,若书写不下时,可以在行尾写入 &符号,并从下行继续书写。</p><p>输入文件的<em><strong>第一行</strong></em>不论写了什么都会被MCNP忽略掉,这一行的作用是方便用户给这个输入文件做一些备注。</p><p>输入文件中有两种注释方法,助记符分别为<code>c </code>(c后有一个空格)和<code>$</code>符号。在第一行写c就是把这一行都注释掉;在某一行的某列上写<code>$</code>就是注释该行该列后的内容。但是即使是注释, 也不能超过每一列80个字符(包括空格)的要求。</p><p>还有三个常用的助记符,分别为r,i,j。r代表的是repeat,例如1 3r 就等于写了 1 1 1 1;i代表线性插入点,例如 1 2i 4 就等于写了 1 2 3 4;j代表的是jump,表示该位置使用默认值,例如1 j 2就等于写了 1 默认值 2,多用于描述重要性部分。</p><h3 id="算例:7MeV轫致辐射X射线角分布、能谱"><a href="#算例:7MeV轫致辐射X射线角分布、能谱" class="headerlink" title="算例:7MeV轫致辐射X射线角分布、能谱"></a>算例:7MeV轫致辐射X射线角分布、能谱</h3><p>在书写MCNP输入文件前,我们首先想好要计算的模型,包括坐标系以及各个物体在这个坐标系内的相对位置。我的计算模型如下图所示。 </p><img src="/54952/uTools_1649142670082.png" class=""><p>计算模型中感兴区是半径为100cm的球内,源是能量为7MeV,位置在(-2,0,0)的单向电子束;X射线靶是半径(Y或者Z方向)1cm,高度(X方向)1cm的金;其他位置均为真空。记录面设置在圈定感兴区的球面上。</p><h4 id="surface-card"><a href="#surface-card" class="headerlink" title="surface card"></a>surface card</h4><p>为了描述出上述模型,我们首先写surface模块,这里需要定义的surface有:</p><ol><li>源所在面</li><li>Au的三个表面(两个底面和一个侧面)</li><li>圈定感兴趣的球面</li><li>划分感兴趣区域表面的记录面</li></ol><p>源所在面书写方法:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1 PX -2 </span><br><span class="line">C 第一个1是指这个面的序号,在cell模块会用到。PX为助记符,表示垂直于X轴的面。-2是该面在X轴上的轴距。</span><br></pre></td></tr></table></figure><p>同理可得Au的三个面分别为:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">2 PX 0</span><br><span class="line">3 PX 1</span><br><span class="line">4 CX 1 </span><br><span class="line">C CX指的是轴心是X轴的圆柱面,1代表半径</span><br></pre></td></tr></table></figure><p>圈定感兴趣的区域的面:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">100 SO 100 </span><br><span class="line">C 第一个100还是面的序号,定义面序号时不需要连续的定义,但要保证定义顺序递增。so代表的是圆心在原点的球面,后面的100就是指半径</span><br></pre></td></tr></table></figure><p>除了上述的面,为了将记录面分割成若干个小面,我们需要额外定义一些分割用辅助面,此处我定义若干圆锥体来分割,以第一个为例:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">30 KX 0 0.234567901 1 </span><br><span class="line">C KX指的是轴心是X轴的圆锥面,0代表顶点在原点,0.234567901代表圆锥顶角的tan值平方。这样的圆锥有两叶,分别在Z>0和Z<0,所以最后的1代表的是我们所需要的Z>0的部分</span><br></pre></td></tr></table></figure><h4 id="cell-card"><a href="#cell-card" class="headerlink" title="cell card"></a>cell card</h4><p>有了这些surface之后我们就能来书写cell部分了。<br>栅元卡有四列数据构成:</p><ol><li>栅元号,栅元号是定义栅元的标识符,相当于给栅元编个号,取个名字。栅元号取值区间[1,99999]。</li><li>材料号,材料号指明了该栅元是由几号材料组成的,同时需要在数据卡的材料卡里对各种材料进行详细说明。0代表真空,不用在数据卡中说明。</li><li>材料密度,指出了材料的密度,加负号是质量密度(g/cm<sup>3</sup>),不加负号为质量密度(1024Atoms/cm<sup>3</sup>)</li><li>构成曲面,指出了栅元是由那些曲面包裹而成。除了最外部的空间,各个栅元都应该是由相应曲面包裹而成的封闭几何体。</li></ol><blockquote><p>假如1号曲面方程为f(x,y,z)=0,则f(x,y,z)<0的部分由“-1”表示,f(x,y,z)>0的部分直接由1表示。 </p><img src="/54952/cell.png" class=""><p>描述栅元时还要用到布尔算符,布尔算符有三个:空格、冒号、井号。空格表示“交”,冒号表示“并”,井号表示“补”。比如100号栅元为“-1”和“-2”相交的空间。 </p><img src="/54952/%E5%B8%83%E5%B0%94%E8%BF%90%E7%AE%97.png" class=""></blockquote><hr><p>回到我们的算例:</p><ol><li>首先定义Au块(cell),它由三个面围成,它们是序号分别为2,3,4。<ol><li>Au块由2号面的向右方向(或X轴的正方向),3号面的向左方向(或X轴的负方向)以及4号面的内部围成。所以这个Au块(cell)的书写方法是:1 1 -19.3 2 -3 -4。</li><li>第一个1代表的是这个cell的序号;</li><li>第二个1代表的是这个cell所对应的材料种类为1,关于1号材料的定义将在后面介绍;</li><li>第三个-19.3中,负号代表的是实际密度,若没有负号则代表的是原子密度。所以-19.3代表的是Au块(cell)的密度是19.3g/cm3;</li><li>之后的2 -3 -4 描述的是Au块是由2号面的正方向,3号面的负方向,4号面的内部围成的。</li></ol></li><li>源不是一个物体,所以不需要在cell块中定义。而在感兴趣内,除了Au块(cell),其他位置均为真空。<ol><li>尽管是真空,我们仍需要在输入文件内把真空定义为一个物体。</li><li>定义的方法如下:2 0 -100 #1。</li><li>其中第一个2代表cell的序号;</li><li>第二个0代表定义的块内什么东西都没有;</li><li>后面的-100 #1限定了这个cell的几何空间,它表示这个块是在100号面的内部,(#助记符代表扣除的意思)除了1号cell的所有空间。</li></ol></li><li>我们同样需要定义感兴区外的空间,定义的方法如下:100 0 100。<ol><li>第一个100是这个cell的序号;</li><li>第二个0代表真空;</li><li>第三个100代表第100号面的外部。</li></ol></li></ol><p>2号cell和100号cell均为真空,区分哪一个是感兴区的方法是利用另外一个助记符imp,它代表的是importance,也就是粒子在该cell内的重要性。<br>这个助记符可以在每个cell的定义的末端写上,也可以在第三块中写入。<br>在cell末端写入的方法如:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">2 0 -100 #1 imp:e,p=1</span><br><span class="line">C 它代表了2号cell中电子(e)及光子(p)的重要性为1,即它是感兴区内的物体</span><br><span class="line">100 0 100 imp:e,p=0</span><br><span class="line">C 它代表了100号cell的电子及光子的重要性为0,即它在感兴区外。</span><br></pre></td></tr></table></figure><blockquote><p>感兴区与非感兴区并不需要一定是位置划分分明的两块区域,我们可以在感兴区内设定一个非感兴区,只要粒子被输运到该区域就会被杀死(类似于黑洞)。</p></blockquote><h4 id="数据卡"><a href="#数据卡" class="headerlink" title="数据卡"></a>数据卡</h4><p>最后我们需要书写第三个模块,在这个模块内将指明模拟计算中所涉及的反应类型,记录方法,运算时间限定等。</p><ol><li><p>模式卡:<code>mode e p</code></p><ul><li>这个卡说明了计算中将涉及两种粒子,分别为电子及光子。(源粒子是电子,它轰击Au块会产生轫致辐射X射线)。</li></ul></li><li><p>材料卡:<code>m1 79197 -1.0</code></p><ul><li>其中m1代表第一号材料,同理会有m2、m3等材料;</li><li>79197的格式是ZZAAA,即79是原子序数(Au),197是质量数;</li><li>-1.0中负号代表的是原子个数的比重,正号则代表的是质量比重。</li><li>材料卡的各种核素的比重的标识中并不要求归一化,MCNP会自动给用户归一化。也就是说 <code>m1 79197 -2.0 79198 -2.0</code>与<code>m1 79197 -0.5 79198 -0.5</code> 的写法对于MCNP而言是等效的,都说明1号材料中<sup>197</sup>Au与<sup>198</sup>Au各占一半,就像SRIM。</li></ul></li><li><p>源定义:<code>sdef par=3 sur=1 pos=-2 0 0 vec=1 0 0 dir=1 erg=7</code></p><ul><li>其中sdef是源定义的助记符代表source definition;</li><li>par代表源粒子的种类,1代表中子,2代表光子,3代表电子;</li><li>sur代表源所在的面,上面定义中sur=1说明源在序号为1的面上;</li><li>pos代表源所在的位置,按照上面的定义,源的位置为(-2,0,0)。请谨记若sur 和pos 同时被用上,请保证pos的点是在sur的面上,不然可能导致计算结果有误;</li><li>vec代表参考向量,向量的起始点是原点,而终止点是(1,0,0)。这说明了我们设定的参考向量就是X轴的正方向;</li><li>dir代表粒子出射方向与参考向量的夹角的余弦,上面定义中为1,说明了源粒子沿着X轴正方向出射;</li><li>erg代表源粒子的能量,按照上面的定义,源粒子的能量为7MeV。</li></ul><blockquote><p>关于源的定义还有许多其他的助记符以及各种分布情况,请参考MCNP的官方使用手册(或者等我填坑(o^^o))。</p></blockquote></li><li><p>粒子重要性表示:<code>imp:e 1 1 0</code></p><ul><li><code>imp:e</code>代表了这张卡描述的是各个cell中电子的重要性</li><li><code>1 1 0</code>代表了在cell块中写的各个cell(以书写顺序)的重要性分别为1、1、0。这说明了cell块中第三个描述的cell(cell的序号可能不是三,只是代表它是第三个被定义的cell。)是电子的黑洞,只要电子被输运到这个cell就会被杀死,停止输运。同理我们还可以定义imp:p 1 1 0。</li><li>在前面已经描述过,这里的imp卡也可以在cell块中写入,不再赘述。</li></ul></li><li><p>能量截断卡:<code>cut:e j 1</code></p><ul><li>其中<code>cut</code>代表能量截断卡的助记符;</li><li><code>e</code>代表电子;</li><li><code>j</code>代表第一个参数选用默认值;</li><li><code>1</code>代表截断能量为1MeV。</li><li>这个卡的作用是当输运过程中,电子的能量小于1MeV,就杀死这个电子。</li><li>这样做的目的是,若我们只关心高能(>1MeV)的X射线,而能量小于1MeV的电子已经不会再产生能量大于1MeV的X射线了,所以我们可以停止这些低能电子输运来节省计算机机时而且不会影响计算结果。</li><li>同理我们还可以写<code>cut:p j 1</code></li></ul></li><li><p>记录方法描述卡1:<code>F1:p 100</code></p><ul><li>其中<code>F1</code>代表的是第一种记录模式,也就是通过某个面的粒子的个数(相对于一个源粒子);</li><li><code>p</code>代表记录的是光子;</li><li><code>100</code>代表记录面是序号为100的面。</li><li>故这个记录卡的作用是记录所有通过100号面的光子。</li></ul></li><li><p>记录方法描述2:<code>F2:p 100</code></p><ul><li>其中<code>F2</code>代表的是第二种记录模式,也就是通过某个面的粒子的注量,它等于通过面的粒子个数(相对于一个源粒子)除以该面的面积。</li></ul></li><li><p>记录面分割:<code>Fs2 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 40 41 42 43 44</code></p><ul><li>其中<code>Fs2</code>代表的是分割第二号记录卡的记录面(也就是分割记录第100号面);</li><li>后面的<code>-30</code> 等代表分割方法,输出时MCNP会给出:<ol><li>100号面上,从30号面的内部(圆锥体右叶的内部)出射的粒子</li><li>100号面上,从30号面的外部且40号面的内部出射的粒子</li><li>100号面上,从30号面的外部且31号面的外部且32号面的内部出射的粒子</li><li>100号面上,从30号面的外部且31号面的外部且32号面的外部且33号面的内部出射的粒子。</li><li>以此类推</li></ol></li></ul></li><li><p>能量分割:我们可以对任意一个记录卡分别设置能量分割卡或所有记录卡同意设置相同的能量分割卡。</p><ul><li>这里我们将对2号记录卡设置一个能量分割卡:<code>E2 1 19i 7</code></li><li>其中<code>E2</code>代表这是对2号记录卡的能量分割卡,后面的<code>1 19i 7</code>代表的是分割方法,也就是在1MeV至7MeV之间插入19个点(若把E2写成E0则代表对所有记录卡使用相同的能量分割方法。)。</li></ul></li><li><p>计算时间设定卡:<code>ctme 10</code></p><ul><li>这个卡说明了要求MCNP计算10分钟。</li><li>可以想象,计算的时间越长,模拟的源粒子的个数就会越多,模拟结果就会越接近它的期望值,统计涨落就会越小。所以计算时间需要用户根据自己希望得到的统计可信度,设定计算时间。</li><li>除了<code>ctme</code>还有利用模拟源粒子的个数进行时间限制的方法如<code>NPS 10000</code>,它说明了需要MCNP模拟10000个源粒子的输运过程(也可以写成<code>NPS 1E4</code>)。</li></ul></li></ol><p>在这个文件中只使用了两个记录方法,分别为F1和F2。<br>MCNP中一共有8中记录方法,我们可以参考使用手册,选用适合计算模型的记录卡。</p><p>此外一种记录卡可以有多个记录面,只要保证记录卡的个位数是8种记录卡的一种,例如F11和F21都是第一种记录类型,即通过某个记录面的粒子个数。</p><p>另外请谨记,在使用F1和F2的记录卡时,记录面一定要是构成某个cell的一个面,不然MCNP不会给出记录结果,也就是说如果用户随意定义了一个面(如上面定义的某个分割面),而且这个面没有被使用在定义某个cell上,那么我们不能期望MCNP可以记录通过这个面的粒子信息。<br>使用分割面时,其实还是记录通过那个记录面的粒子个数,分割面只是把那个记录面分割为若个块而已。</p><h4 id="总结-输入文件"><a href="#总结-输入文件" class="headerlink" title="总结-输入文件"></a>总结-输入文件</h4><p>总结上文,得输入文件为:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line">X-ray Ener=7MeV</span><br><span class="line">c cell card</span><br><span class="line">1 1 -19.3 2 -3 -4 $ Au </span><br><span class="line">2 0 -100 #1 </span><br><span class="line">100 0 100</span><br><span class="line"></span><br><span class="line">c surface card</span><br><span class="line">c radiation source</span><br><span class="line">1 px -2 $ 放射源所在面</span><br><span class="line">2 px 0 </span><br><span class="line">3 px 1 </span><br><span class="line">4 cx 1 </span><br><span class="line">30 kx 0 0.234567901 1</span><br><span class="line">31 kx 0 0.5625 1</span><br><span class="line">32 kx 0 1.040816327 1</span><br><span class="line">33 kx 0 1.777777778 1</span><br><span class="line">34 kx 0 3 1</span><br><span class="line">35 kx 0 5.25 1</span><br><span class="line">36 kx 0 10.11111111 1</span><br><span class="line">37 kx 0 24 1</span><br><span class="line">38 kx 0 99 1</span><br><span class="line">39 kx 0 1e33 1</span><br><span class="line">40 kx 0 99 -1</span><br><span class="line">41 kx 0 24 -1</span><br><span class="line">42 kx 0 10.11111111 -1</span><br><span class="line">43 kx 0 5.25 -1</span><br><span class="line">44 kx 0 3 -1</span><br><span class="line">45 kx 0 1.777777778 -1</span><br><span class="line">46 kx 0 1.040816327 -1</span><br><span class="line">47 kx 0 0.5625 -1</span><br><span class="line">48 kx 0 0.234567901 -1</span><br><span class="line">49 kx 0 0 -1</span><br><span class="line">100 so 100</span><br><span class="line"></span><br><span class="line">mode e p</span><br><span class="line">m1 79197 -1.0 $ Au </span><br><span class="line">sdef par=3 sur=1 pos=-2 0 0 vec=1 0 0 dir=1 erg=7 </span><br><span class="line">imp:e 1 1 0</span><br><span class="line">imp:p 1 1 0</span><br><span class="line">cut:e j 1</span><br><span class="line">cut:p j 1</span><br><span class="line">F1:p 100</span><br><span class="line">F2:p 100</span><br><span class="line">Fs2 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 40 41 42 43 44 &</span><br><span class="line"> 45 46 47 48 </span><br><span class="line">E2 1 19i 7</span><br><span class="line">ctme 10</span><br></pre></td></tr></table></figure><blockquote><p>注意,该输入文件共有两个空行,用来分割 cell card & surface card & data card。MCNP对于输入文件格式要求很严格,应注意。</p></blockquote><h4 id="关于vise-exe"><a href="#关于vise-exe" class="headerlink" title="关于vise.exe"></a>关于vise.exe</h4><p>我们可以利用vised.exe观察这个已经写好的输入文件的模型,如果书写有误,我们需要修改输入文件。<br>有错误时会导致vised.exe无法打开文件并被强制关闭。<br>出现这种情况时,请看输入文件的书写规范,如空行是否多了或少了等。</p><p>若打开后,观察到明确的红线,代表两个物体分享了一部分空间,这在MCNP中是不允许的。</p><p>在书写复杂的模型时,vised.exe可以帮助我们确定写出来的模型与我们想像的模型是一致的。我们应反复地观察各个方向的视图,从而确保输入文件的正确性,不然计算出来的结果就很有可能是错误的。</p><p>Vised.exe是windows下的应用程序,我们双击它并用它打开我们已经书写好的输入文件,就可以观察写好的模型了,操作简单不做赘述。</p><h2 id="输出文件解读"><a href="#输出文件解读" class="headerlink" title="输出文件解读"></a>输出文件解读</h2><p>利用MCNP 计算上面的输入文件可以得到同名的、拓展名为o的文件。使用文本编辑器打开它,搜索关键字:<code>tally</code> 找到如下部分:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">1tally 1 nps = 2958959</span><br><span class="line"> tally type 1 number of particles crossing a surface. </span><br><span class="line"> tally for photons </span><br><span class="line"> </span><br><span class="line"> surface 100 </span><br><span class="line"> 2.90042E-01 0.0010</span><br></pre></td></tr></table></figure><p>这是输出文件中关于记录信息的结果部分。</p><ul><li><p><code>nps</code> 代表了一共运行了2958959个粒子的输运过程 </p></li><li><p><code>tally type 1</code> 代表记录类型是1,也就是<code>number of particles crossing a surface</code> </p></li><li><p><code>tally for photons</code> 代表记录的是光子 </p></li><li><p><code>surface 100</code> 代表记录的是第100号面 </p></li><li><p>记录结果是:<code>2.90042E-01 0.0010</code></p><ul><li>它代表有1个7MeV的电子轰击1cm的Au时,会有0.29个能量大于1MeV(我们在cut中限定了能量)光子透过第100号记录面,而这个数据的相对误差为0.001。</li></ul></li></ul><p>第二号记录结果如下:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line">1tally 2 nps = 2958959</span><br><span class="line"> tally type 2 particle flux averaged over a surface. units 1/cm**2 </span><br><span class="line"> tally for photons </span><br><span class="line"> areas </span><br><span class="line"> surface: 100 </span><br><span class="line"> segment</span><br><span class="line"> 1 6.28319E+03</span><br><span class="line"> 2 6.28319E+03</span><br><span class="line"> 3 6.28319E+03</span><br><span class="line"> 4 6.28319E+03</span><br><span class="line"> 5 6.28319E+03</span><br><span class="line"> 6 6.28319E+03</span><br><span class="line"> 7 6.28319E+03</span><br><span class="line"> 8 6.28319E+03</span><br><span class="line"> 9 6.28319E+03</span><br><span class="line"> 10 6.28319E+03</span><br><span class="line"> 11 6.28319E+03</span><br><span class="line"> 12 6.28319E+03</span><br><span class="line"> 13 6.28319E+03</span><br><span class="line"> 14 6.28319E+03</span><br><span class="line"> 15 6.28319E+03</span><br><span class="line"> 16 6.28319E+03</span><br><span class="line"> 17 6.28319E+03</span><br><span class="line"> 18 6.28319E+03</span><br><span class="line"> 19 6.28319E+03</span><br><span class="line"> 20 6.28319E+03</span><br><span class="line"> ......</span><br></pre></td></tr></table></figure><ul><li><code>nps</code>代表一共运行了2958959个源粒子的输运过程。</li><li><code>Tally type 1</code> 代表记录类型为2,也就是<code>particle flux averaged over a surface</code>,请注意它的单位是1/cm<sup>2</sup>。</li><li><code>Tally for photons</code>代表的是记录的是光子。</li><li><code>Surface 100</code> 代表记录面是第100号面。</li><li><code>Segment</code> 代表的是利用分割面分割后,100号面的各个子面的面积。<blockquote><p>由于我们使用的等立体角分割,所以各个子面的面积均相同</p></blockquote></li></ul><p>其他记录结果:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line">surface 100 </span><br><span class="line"> segment: -30 </span><br><span class="line"> energy</span><br><span class="line"> 1.0000E+00 0.00000E+00 0.0000</span><br><span class="line"> 1.3000E+00 1.58985E-06 0.0058</span><br><span class="line"> 1.6000E+00 1.25669E-06 0.0065</span><br><span class="line"> 1.9000E+00 1.01556E-06 0.0073</span><br><span class="line"> 2.2000E+00 8.05683E-07 0.0082</span><br><span class="line"> 2.5000E+00 6.50129E-07 0.0091</span><br><span class="line"> 2.8000E+00 5.29430E-07 0.0101</span><br><span class="line"> 3.1000E+00 4.41488E-07 0.0110</span><br><span class="line"> 3.4000E+00 3.71080E-07 0.0120</span><br><span class="line"> 3.7000E+00 3.09977E-07 0.0132</span><br><span class="line"> 4.0000E+00 2.59094E-07 0.0144</span><br><span class="line"> 4.3000E+00 2.11708E-07 0.0159</span><br><span class="line"> 4.6000E+00 1.80941E-07 0.0172</span><br><span class="line"> 4.9000E+00 1.59103E-07 0.0184</span><br><span class="line"> 5.2000E+00 1.31403E-07 0.0202</span><br><span class="line"> 5.5000E+00 1.04079E-07 0.0227</span><br><span class="line"> 5.8000E+00 8.97713E-08 0.0245</span><br><span class="line"> 6.1000E+00 6.86866E-08 0.0280</span><br><span class="line"> 6.4000E+00 4.88390E-08 0.0332</span><br><span class="line"> 6.7000E+00 2.82384E-08 0.0436</span><br><span class="line"> 7.0000E+00 1.05423E-08 0.0714</span><br><span class="line"> total 8.26230E-06 0.0025</span><br><span class="line"> </span><br><span class="line"> surface 100 </span><br><span class="line"> segment: 30 -31 </span><br><span class="line"> energy</span><br><span class="line"> 1.0000E+00 0.00000E+00 0.0000</span><br><span class="line"> 1.3000E+00 9.48975E-07 0.0075</span><br><span class="line"> 1.6000E+00 7.33985E-07 0.0086</span><br><span class="line"> 1.9000E+00 5.56701E-07 0.0098</span><br><span class="line"> 2.2000E+00 4.35679E-07 0.0111</span><br><span class="line"> 2.5000E+00 3.35311E-07 0.0127</span><br><span class="line"> 2.8000E+00 2.73079E-07 0.0140</span><br><span class="line"> 3.1000E+00 2.10847E-07 0.0160</span><br><span class="line"> .....</span><br></pre></td></tr></table></figure><p>其中:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">surface 100 </span><br><span class="line"> segment: -30</span><br></pre></td></tr></table></figure><p>代表统计的是从记录面100且从分割面30的内部(圆锥右叶的内部)通过的光子。<br>同理,</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">surface 100 </span><br><span class="line"> segment: 30 -31 </span><br></pre></td></tr></table></figure><p>代表的是统计的是从记录面100且从分割面30的外部且从分割面31的内部通过的光子。</p><p>对于:</p><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">1.0000E+00 0.00000E+00 0.0000</span><br><span class="line">1.3000E+00 1.58985E-06 0.0058</span><br><span class="line">1.6000E+00 1.25669E-06 0.0065</span><br></pre></td></tr></table></figure><p>最左边一列代表的是能量,第二列代表的是概率,第三列代表的是第二列的相对误差。</p><p>对于这三行统计结果的解读如下,在相应的记录面内,</p><ul><li>能量为0~1MeV的光子的注量为0,这是因为我们把能量小于1MeV的光子都杀死了(利用cut卡)。</li><li>能量为1~1.3MeV的光子的注量为1.58985E-6,单位是1/cm<sup>2</sup>,且是相对于一个电子。</li><li>能量为1.3~1.6MeV的光子的注量为1.25669E-06,单位是1/cm<sup>2</sup>,且是相对于一个电子。</li><li>以此类推。</li></ul><h2 id="结束语"><a href="#结束语" class="headerlink" title="结束语"></a>结束语</h2><p>感觉没啥可写的了,剩下的都在手册里或者不难找到。有啥疑问我们评论区聊(评论托管服务器在国外,可能会偶尔渲染不出来大家可以试着多进几次)。</p><h3 id="关于使用bat文件配置环境变量的问题"><a href="#关于使用bat文件配置环境变量的问题" class="headerlink" title="关于使用bat文件配置环境变量的问题"></a>关于使用bat文件配置环境变量的问题</h3><p>我们可以使用快捷键 WIN+S 搜索<code>环境变量</code>,打开<code>编辑环境变量</code>进入如下截面:</p><img src="/54952/%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F.png" class=""><p>首先双击 Path,然后点击新建,将bat文件<strong>注意是bat文件</strong>所在的路径添加进去。该操作的意义是只有在Path内的路径才能使用cmd。<br>bat文件可以不放在MCNP根目录,只要确保bat文件与输入文件在同一目录下即可。</p><p>最后的最后,附上我写的bat文件(可以删除中间文件),大家看看能不能用~</p><p>calculate:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">::设置输入文件和输出结果文件名</span><br><span class="line"><span class="built_in">set</span> inp=test.i</span><br><span class="line"><span class="built_in">set</span> outp=test.o</span><br><span class="line"></span><br><span class="line">::删除旧文件</span><br><span class="line"><span class="keyword">if</span> <span class="keyword">exist</span> <span class="variable">%outp%</span> <span class="built_in">del</span> <span class="variable">%outp%</span></span><br><span class="line"></span><br><span class="line">::调用MCNP开始计算</span><br><span class="line"><span class="keyword">call</span> mcnp5.exe i=<span class="variable">%inp%</span> o=<span class="variable">%outp%</span></span><br><span class="line"></span><br><span class="line">::删除各类中间备份转储文件(应该是这么几个)</span><br><span class="line"><span class="built_in">del</span> runtp*</span><br><span class="line"><span class="built_in">del</span> dcinp</span><br><span class="line"><span class="built_in">del</span> ddinp</span><br><span class="line"><span class="built_in">del</span> dfill</span><br><span class="line"><span class="built_in">del</span> inp </span><br><span class="line"><span class="built_in">del</span> out*</span><br><span class="line"><span class="built_in">del</span> *.sav</span><br></pre></td></tr></table></figure><p>draw:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">call</span> vised.exe</span><br><span class="line"></span><br><span class="line"><span class="built_in">del</span> *.o</span><br><span class="line"><span class="built_in">del</span> runtp*</span><br><span class="line"></span><br><span class="line"><span class="built_in">del</span> dcinp</span><br><span class="line"><span class="built_in">del</span> ddinp</span><br><span class="line"><span class="built_in">del</span> dfill</span><br><span class="line"><span class="built_in">del</span> inp </span><br><span class="line"><span class="built_in">del</span> out*</span><br><span class="line"><span class="built_in">del</span> *.sav</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>MCNP5入门搬运学习,搬砖永无止境</p></summary>
<category term="MCNP5" scheme="http://paneersblog.github.io/tags/MCNP5/"/>
</entry>
<entry>
<title>Chapter_1</title>
<link href="http://paneersblog.github.io/28793.html"/>
<id>http://paneersblog.github.io/28793.html</id>
<published>2022-02-27T04:35:02.000Z</published>
<updated>2022-07-16T09:29:30.028Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>专业英语词汇表</p><span id="more"></span><table><thead><tr><th align="left">Chapter-1-words</th><th align="left"></th></tr></thead><tbody><tr><td align="left">material world</td><td align="left">物质世界</td></tr><tr><td align="left">distinguish</td><td align="left">区别,辨别</td></tr><tr><td align="left">chemical,mechanical,electrical properties</td><td align="left">化学、力学、电学性质</td></tr><tr><td align="left">physical state</td><td align="left">物理状态</td></tr><tr><td align="left">plasma</td><td align="left">等离子体</td></tr><tr><td align="left">apparent</td><td align="left">显然的,外观的</td></tr><tr><td align="left">distinct</td><td align="left">截然不同的,独特的</td></tr><tr><td align="left">diversity</td><td align="left">差异,多样性</td></tr><tr><td align="left">element</td><td align="left">元素</td></tr><tr><td align="left">bond</td><td align="left">结合 联结</td></tr><tr><td align="left">in turn</td><td align="left">依次,轮流</td></tr><tr><td align="left">arise from</td><td align="left">起于</td></tr><tr><td align="left">basic particle</td><td align="left">基本粒子</td></tr><tr><td align="left">electrons,protons,neutrons</td><td align="left">电子、质子、中子</td></tr><tr><td align="left">internal forces and energy</td><td align="left">内力和内能</td></tr><tr><td align="left">gravitational,electrostatic,electromagnetic,nuclear force</td><td align="left">引(重)力、静电力、电磁力、核力</td></tr><tr><td align="left">ability to do work</td><td align="left">做功的本领(能力)</td></tr><tr><td align="left">stored,released,transformed,transferred,“used” energy</td><td align="left">能量的存储、释放、转换、转移、使用</td></tr><tr><td align="left">entity</td><td align="left">实体</td></tr><tr><td align="left">vice versa</td><td align="left">反之亦然</td></tr><tr><td align="left">review</td><td align="left">回顾,复习</td></tr><tr><td align="left">recall</td><td align="left">回忆,回想,记起</td></tr><tr><td align="left">product (quotient,sum,difference)</td><td align="left">乘积(商、和、差)</td></tr><tr><td align="left">muscles</td><td align="left">肌肉</td></tr><tr><td align="left">object</td><td align="left">物体</td></tr><tr><td align="left">potential (kinetic) energy</td><td align="left">势(动)能</td></tr><tr><td align="left">rest</td><td align="left">静止 其余</td></tr><tr><td align="left">Newton’s law</td><td align="left">牛顿定律</td></tr><tr><td align="left">law(theorem,definition)</td><td align="left">定律(定义、定理)</td></tr><tr><td align="left">mass(m),acceleration(a),speed(v)</td><td align="left">质量、加速度、速度</td></tr><tr><td align="left">conservation of energy</td><td align="left">能量守恒</td></tr><tr><td align="left">(conversation</td><td align="left">会话;谈话)</td></tr><tr><td align="left">hydroelectric plant</td><td align="left">水电厂</td></tr><tr><td align="left">turbine</td><td align="left">汽轮机,涡轮机</td></tr><tr><td align="left">electric generator</td><td align="left">发电机</td></tr><tr><td align="left">blade</td><td align="left">叶片</td></tr><tr><td align="left">joule(J)</td><td align="left">焦耳</td></tr><tr><td align="left">friction</td><td align="left">摩檫</td></tr><tr><td align="left">electrical potential difference</td><td align="left">电位势</td></tr><tr><td align="left">charged particles</td><td align="left">带电粒子</td></tr><tr><td align="left">automobile (motor car)</td><td align="left">汽车</td></tr><tr><td align="left">a storage battery</td><td align="left">蓄电池</td></tr><tr><td align="left">mechanical parts</td><td align="left">机械部件</td></tr><tr><td align="left">thermodynamics</td><td align="left">热力学</td></tr><tr><td align="left">specify</td><td align="left">详述,载明</td></tr><tr><td align="left">inherent</td><td align="left">固有的,天生的</td></tr><tr><td align="left">convert</td><td align="left">转变,变换</td></tr><tr><td align="left">petroleum</td><td align="left">石油</td></tr><tr><td align="left">fossil</td><td align="left">化石,远古生物形成的</td></tr><tr><td align="left">nuclear reaction</td><td align="left">核反应</td></tr><tr><td align="left">intimate</td><td align="left">亲密的,熟悉的,私人的</td></tr><tr><td align="left">fission</td><td align="left">裂变</td></tr><tr><td align="left">thermometer</td><td align="left">温度计</td></tr><tr><td align="left">specific heat capacity</td><td align="left">比热</td></tr><tr><td align="left">macroscopic</td><td align="left">宏观的</td></tr><tr><td align="left">microscopic</td><td align="left">微观的</td></tr><tr><td align="left">Celsius scale</td><td align="left">摄氏温标</td></tr><tr><td align="left">Kelvin scale</td><td align="left">开氏温标</td></tr><tr><td align="left">translational motion</td><td align="left">平动</td></tr><tr><td align="left">Boltzmann’s constant</td><td align="left">玻尔兹曼常数(K)</td></tr><tr><td align="left">proportional to</td><td align="left">正比于</td></tr><tr><td align="left">appreciate</td><td align="left">估价,理解</td></tr><tr><td align="left">inversely proportional to</td><td align="left">反比于</td></tr><tr><td align="left">prefix</td><td align="left">前缀,词首(postfix 后缀,词尾)</td></tr><tr><td align="left">astronomical</td><td align="left">天文的,极大的</td></tr><tr><td align="left">submicroscopic</td><td align="left">亚微观的</td></tr><tr><td align="left">oscillation</td><td align="left">振荡,振动</td></tr><tr><td align="left">transmitter</td><td align="left">无线电,电视讯号发送装置</td></tr><tr><td align="left">X-ray</td><td align="left">X 射线</td></tr><tr><td align="left">gamma ray</td><td align="left">γ 射线</td></tr><tr><td align="left">sophisticate</td><td align="left">改进,采用先进技术,完善</td></tr><tr><td align="left">gasoline</td><td align="left">汽油</td></tr><tr><td align="left">dissociate</td><td align="left">分离</td></tr><tr><td align="left">latent energy</td><td align="left">潜能</td></tr><tr><td align="left">fusion</td><td align="left">熔解,聚变</td></tr><tr><td align="left">agitation</td><td align="left">激发,搅拌</td></tr><tr><td align="left">theory</td><td align="left">理论 (experiment 实验)</td></tr><tr><td align="left">rigor</td><td align="left">精确</td></tr><tr><td align="left">special relativity</td><td align="left">狭义相对论</td></tr><tr><td align="left">rest mass</td><td align="left">静止质量</td></tr><tr><td align="left">impart</td><td align="left">给予,传授</td></tr><tr><td align="left">startling</td><td align="left">令人吃惊的</td></tr><tr><td align="left">viz.</td><td align="left">即</td></tr><tr><td align="left">consume</td><td align="left">消耗,消费</td></tr><tr><td align="left">magnitude</td><td align="left">大小,数量,量级</td></tr><tr><td align="left">dimensions</td><td align="left">尺寸,尺度,维(数),度(数),元</td></tr><tr><td align="left">efficient</td><td align="left">有效的,效率高的</td></tr><tr><td align="left">discrepancy</td><td align="left">差异,矛盾</td></tr><tr><td align="left">vital</td><td align="left">至关重要的,所必需的</td></tr><tr><td align="left">long-term</td><td align="left">长期</td></tr><tr><td align="left">survival</td><td align="left">幸存,生存</td></tr><tr><td align="left">crisis</td><td align="left">危机</td></tr><tr><td align="left">scarce</td><td align="left">缺乏的,稀有的</td></tr><tr><td align="left">inequitable</td><td align="left">不公平的</td></tr></tbody></table>]]></content>
<summary type="html"><p>专业英语词汇表</p></summary>
<category term="英语学习" scheme="http://paneersblog.github.io/categories/%E8%8B%B1%E8%AF%AD%E5%AD%A6%E4%B9%A0/"/>
<category term="WordList_P" scheme="http://paneersblog.github.io/tags/WordList-P/"/>
</entry>
<entry>
<title>SRIM入门(四)</title>
<link href="http://paneersblog.github.io/6067.html"/>
<id>http://paneersblog.github.io/6067.html</id>
<published>2022-02-22T16:34:54.000Z</published>
<updated>2022-07-16T09:31:23.182Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>demo4 靶损伤计算</p><span id="more"></span><p>前文已经说明了如何在单质硅上创建一个掺杂剂量峰深度为250纳米,分布约为每平方厘米 5E18个原子的互补金属氧化物n型井。<br>问题是选择正确的掺杂物,并确定合适的注入能量和剂量(离子/平方厘米)来获得这个n型井。demo1得出的结论是采用能量为 190keV的磷离子,注入剂量为每平方厘米10<sup>14</sup>个离子</p><p>在这部分我们继续使用demo1中的靶来进行详细阐述离子对靶的损伤计算。</p><p>通常,在室温300K下的注入产生的绝大部分损伤将由于“自退火”而复合。在室温下,晶格原子具有足够的能量使得简单的靶损伤重新形成晶体而使靶损伤消失。一般情况下,相比半导体硅的自退火,金属的要快,而绝缘体的要慢,因而一个硅靶是一个不错的例子。<br>然而 SRIM没有考虑热效应,因而我们计算的注入损伤发生在温度为OK的情况下。忽略热效应会改变最终损伤的大小,但我们要讨论的基本损伤种类仍会产生。</p><p>首先我们按照 demo1中描述的方法在 SRIM中进行相同设置并计算。</p><blockquote><ol><li>打开 SRIM并点击 TRIM Calculation</li><li>选择 INO DATA,点击 PT选择磷元素,设置其能量为 190keV</li><li>在靶数据中选择硅,设置其厚度为 3500Ang</li><li>在界面右上角将 DAMAGE选项选择 Detailed Calculation with Full Damage Cascades</li><li>按下 Save Input and Run TRIM开始计算</li></ol></blockquote><p>我们可以看到,计算得出的图像展示了每个离子的计算结果。<br><strong>红色</strong>的小点是离子和靶原子之间的碰撞,在这些碰撞中靶原子从它们原来的晶格位置中被撞击出来。<br><strong>绿色</strong>的点是在反冲靶原子硅和其它靶原子之间的碰撞。<br>反冲靶原子造成级联碰撞在损伤过程中占据多数。只有当能量转移大到可以将原子撞击出其晶格位置时这些点才会被绘入图中。这样一来这个图像展示了已经发生错位的原子数量。<br><strong>每个离子停止的地方用黑色的点</strong>,但是单独的一个黑色像素点太小了,以至于在现代高分辨率的屏幕上很难看到。</p><p>注意到左上角的“ION”重复离子信息的选项框。注意,“TARGET DATA”窗口包含了所有的靶信息(你可能需要使用光标展开这个窗口)。<br>其中的一些信息可能不是你输入的,例如位错能(DisplacementEnergy: 15eK)、表面束缚能(SurfaceBinding Energy: 4.7eV)和晶格束缚能(LatticeBindingEnergy: 2eV)。这些给出的数值是硅的默认值。</p><p>TRIM是一个很灵活的软件,点击 Pause暂停计算,然后点击 Change TRIM。此时我们可以改变输入的值来修改计算。</p><p>例如我们可以将反冲原子由绿色改为蓝色。<br>点击标记为 “Moving Atom Colors”的颜色方框,会弹出一个调色板,选择蓝色(或者别的),然后依次点 “OK” “End Edit” “Continue”。<br>当新的反冲硅原子产生一个空位时他们将会被标记为蓝色(这些蓝色的小点会被大量绿色的“阻止原子”硅所淹没,但应该可能在级联碰撞中看到一些)。</p><p>注意在一张离子径这一些离子看起来正在从右端离开靶。这个靶要阻止所有的离子还不够深。<br>要修正这一点,点击来暂停 Pause计算。然后在 Target Data 窗口中点击 Width(A)中的 3500。将弹出一个窗口,从中我们可以把深度改变为4000。你同样需要改变左边图像窗口中的 Plot Window,这里也要改成4000,这样你才能看到这个靶深度。<br>完成这个修正后,依次点击 “End Edit” “Continue” 我们在 TRIM中进行了一项非常基础性的改变,计算将会重新开始。图像必然会随之改变,它现在展示了 O-4000A深度的情形。并且我们会看到现在所有的离子都在它们离开图像右端之前停止下来了。</p><p>进行这项练习的目的是告诉你没有必要知道所有的变量才开始 TRIM。因为可能你不确定射程最远的离子所能到达的位置。<br>你可以用一个粗略的值开始TRIM计算,然后在你看到了实际的情形后可以将它们改变到更加合理的值。</p><p>接下来我们插入一点学科背景,trim此时可以继续计算。</p><hr><p>背景—“级联反冲中的物理原理”</p><p>这个部分探讨对载能离子给固体靶造成损伤的估计中需要使用的术概念。我们首先需要阐明一些基础的概念。</p><p>靶损伤中不同的部分定义如下: </p><ul><li>位错:一个载能入射粒子将一个晶格原子撞击出它初始位置的过程。 </li><li>空位:一个空的晶格位置(没有原子)。一开始所有的晶格位置都被占据,然后位错过程产生了空位。 </li><li>填隙原子:晶体中的原子被撞击出原有的位置并停留在固体中。当入射到固体中的离子停留在固体中时,也被视为填隙原子。</li><li>碰撞复位:填充了空位的和初始原子相同(这一点将会在下面讨论)的新原子。这是唯一可以让空位可以被复合的机制。</li><li>位错能(E<sub>disp</sub>):即将一个靶原子从其晶格中的位置撞击出足够远的距离使得它无法迅速回位所需要的最小能量。这个最小能量产生一个弗仑克尔对,即一个空位和一个临近的填隙原子,而这是离子产生的损伤中最基本的一种类型。</li><li>晶格束缚(E<sub>latt</sub>):将一个原子从晶格中移除出来所需要的最小能量。克服电子束缚并将原子从晶格中移位出来是需要能量的,因而这部分被转移到反冲原子中的能量被丢失了。晶格结合能必然小于错位能。</li><li>表面束缚能(E<sub>surf</sub>):靶表面的原子在靠近表面一端未被束缚,因而将其从晶格位置中移除出来所需的能量相比在固体内部被其他原子包围时要小。一个表面原子具有更少的电子束缚需要被打破。这个能量在计算溅射(表面原子的移除)时特别重要。</li><li>运动原子的最终能量(E<sub>final</sub>):具有低于该能量的原子被认为是静止在固体中的。离子动能的计算必须在某个最小能量下停止。不同过程的能量损失在离子减速时变得更小,而一个最小能量能产生一个更有效的计算结果。最终能量小于上面任意个能量。</li></ul><p>对于硅靶,默认值为:E<sub>disp</sub>=15eV,E<sub>latt</sub>=2eV,E<sub>surf</sub>=4.7eV以及E<sub>final</sub>=2eV。</p><p>如果一个运动的原子撞击了一个靶原子,并且传递给了后者超过 E<sub>disp</sub> 的能量,那么靶原子将会被撞击出其晶格位置。由于它将损失 E<sub>latt</sub> 的能量到晶格中去,因而它的反冲能量E<sub>recoil</sub>=E<sub>disp</sub>-E<sub>latt</sub>。如果反冲靶原子的能量大于 E<sub>disp</sub>,那么它将继续通过撞击其它靶原子来产生更多的空位。</p><p>另外,有一种特殊的损伤必须要考虑到。<br>如果入射原子与它撞击的原子是相同的元素,那么入射粒子可能会将其能量转移给靶原子,将它撞击出晶格位置,而入射原子将会占据靶原子在晶格中的位置,这被称为复位碰撞。尽管听起来很复杂,但是这种机制可能会降低总空位的30%。要发生复位碰撞有需要满足三个基本条件:</p><ol><li>入射原子必须和靶原子相同。</li><li>入射粒子残留的能量必须小于 E<sub>final</sub>(它必须停下来)。</li><li>被撞击的原子必须拥有足够的能量来继续移动,也就是说它的能量要大于 E<sub>disp</sub></li></ol><p>计算级联反冲、靶损伤、复位碰撞等过程需要特定的假设,下面来明确其定义:</p><ol><li>假设入射粒子原子序数为 Z<sub>1</sub>,能量为 E,它和原子序数为 Z<sub>2</sub>的靶原子发生碰撞。在碰撞之后入射粒子能量为 E<sub>1</sub> 并且被撞击原子能量为E<sub>2</sub>。</li><li>当 E<sub>2</sub> > E<sub>disp</sub>(被撞击原子得到了足够的能量离开原来的位置)时会产生位错。当E<sub>1</sub> > E<sub>disp</sub> 和 E<sub>2</sub> > E<sub>disp</sub>(两个原子都有足够的能量离开碰撞位置)同时满足时空位就会产生。之后两个原子都会变产级联碰撞中的运动原子。原子 Z<sub>2</sub>的能量 E<sub>2</sub>在它进行下一个碰撞之前会因为 E<sub>latt</sub>减小。如果 E<sub>2</sub> < E<sub>disp</sub>,那么被撞击原子没有足够的能量,因而它将通过振动返回到它原来的位置并以声子(晶体中晶格振动沉积的能量)的形式释放出能量 E<sub>2</sub>。</li><li>在一个碰撞以后如果E<sub>1</sub> < E<sub>disp</sub>,E<sub>2</sub> > E<sub>disp</sub>并且 Z<sub>1</sub> ≠ Z<sub>2</sub>,那么入射原子将会在碰撞处停下而形成复位碰撞,其中 E<sub>1</sub>的能量以声子的形式被释放。晶格位置中的原子通过交换保持为相同种类的原子。这种形式的碰撞在单元素靶中发生大的级联反冲时是很常见的。如果 E<sub>1</sub> < E<sub>disp</sub>,E<sub>2</sub>>E<sub>disp</sub>并且 Z<sub>1</sub> ≠ Z<sub>2</sub>,那么 Z<sub>1</sub>变成了停止下来的填隙原子。</li><li>最后,如果E<sub>1</sub> < E<sub>disp</sub>并且E<sub>2</sub> < E<sub>disp</sub>,那么Z<sub>1</sub>将变成填隙原子,而E<sub>1</sub>+E<sub>2</sub>以声子的形式被释放。如果你的靶内有几种不同的元素,并且每一种都有一个不同的错位能,那么当每个级联反冲原子在撞击不同靶原子时E<sub>disp</sub>将会变化。</li></ol><p>这些不同损伤类型的总和是相关的。用两个方程可以描述:</p><p>$$<br>错位=空位+复位碰撞<br>$$<br>$$<br>空位+复位原子=填隙原子+离开靶的原子<br>$$</p><p>如果一个级联反冲原子离开了靶,它就不再被跟踪了。也就是说如果它离开了靶的前表面或者后表面,他就被程序丢弃了。<br>TRIM会不停地追踪在靶内部侧向运动的原子,即使它们已经离开了屏幕显示的范围。但是一旦它们穿过了靶的任何一个表面,它们就被丢弃了,不再被计数。<br>这也是靶内部产生了空位,且一个运动的反冲原子最后停留的地方可能离它产生的空位有一段距离的原因。如果一个反冲原子离开了靶,很显然填隙原子的总数与空位的总数相比将会有一个差额,这个差额就是以某种形式脱离靶的原子数。每个复位碰撞会减少空位数并减少一个填隙原子,这使得上面的第第一个方程得以平衡。</p><p>对于 TRIM快速计算靶损伤,TRIM使用了Kinchin-Pease解析法,关于其背景可参考如下文献(博主表示我就不看了QaQ):</p><ol><li>Kinchin and R.S. Pease, Rep.Prog.Phys.,Vol.18,1(1955).</li><li>P.Sigmund, Rad.Eff,.Vol.1,15(1969).</li><li>M.J.Noregett, M.T.Robinson and I.M.Torrens,Nuci.Eng.Design,Vol.33,50(1974).</li></ol><hr><p>现在我们来看两种简单的图像:电离和声子</p><p><strong>电离能损</strong>是指损失给靶电子的能量。靶中的电子会从快速运动的离子和反冲原子中获得能量,然后以热量(金属靶)或者声子(绝缘体靶)的形式来释放掉这部分能量。</p><p><strong>声子</strong>是在晶体中的原子震荡能。由于晶体中所有的原子都是相关的,当你使它们中的一个开始震荡时,其他原子也会开始震荡。由于从某种意义上来说它是量子化的(特定的震荡模式具有优越性),这种质量震荡被描述为声子。</p><p>如果你的 TRIM还在运行,我们继续往下说。</p><p>通过点击在作图窗口中的选项框打开电离图(在前面查看作图工具的介绍)。<br>这里有两种不同的图像,一种是从入射离子中损失给电子的能量,而另一个是从反冲靶原子中损失给电子的能量。通常来说,离子具有更大的电离能损,但是并不是对所有的离子/靶的组合是这样的。电子对与其运动速度近似的粒子能量的吸收具有最高的效率。相比反冲硅靶原子,入射离子运动的快得多。所以离子损失更多的能量给靶电子。</p><p>关闭电离图,打开声子图。</p><p>这个图像展示了声子能损相比电离能损非常不同。<br>你很难可以看到从离子(图像底部的红色线)中损失能量给声子,而声子几乎全是通过反冲靶原子产生的。<br>这些反冲声子由何而来,我们还不是十分清楚(将有另一张图像对此进行解释),但是你可以查看名为Calculation Parameters的窗口。这个名为“%Energy Loss”的部分展示了每个离子的入射能量(190keV)是如何耗散的。<br>名为Phonons的一行显示离子只将其约0.44%的一小部分能量损失给了声子(190keV×0.44%=836eV),而反冲原子转移了约为 30%的能量给声子(190keV×29%=55keV)。</p><p>那么,声子是如何产生的呢?</p><p>声子来自于几种途径。 </p><p>当一个原子从它们晶格中的位置被撞击出来时,它的结合能 E<sub>latt</sub>=2eV被转移到反冲原子产生的声子中。如果你查看 TRIM中右上角的选项框,你将会看到每个离子产生的空位数,Vacancies/Ion(空位/离子比)约为2300。因而对于每个离子,通过离子或者级联反冲产生的错位能产生2300×2eV=4600eV的声子。</p><p>剩下的声子是由撞击到晶格原子并转移了小于E<sub>disp</sub>的能量的离子或者反冲原子产生的。<br>至少E<sub>disp</sub> 的能量需要被转移到靶原子中才能将它从本身的位置中驱逐出去。那如果转移的能量小于这个值会发生什么呢?那么靶原子会反冲并震荡一会儿,但由于没有足够能量冲出原来的位置,最终这个能量会被转移给新的声子。</p><p>在 TRIM 右边名为 %EnergyLoss的选项框可以将入射粒子能量以包括声子的不同类型进行统计。入射粒子会将其入射能量190keV的 0.44%产生声子,而反冲原子贡献了额外的 28.8%,两者总共为 29.2%。乘以离子总能量,可以得到每个入射离子产生 190keV×29.2%=55keV的声子。假设声子直接附加到靶温度中去,这会使得靶变得非常炽热。</p><p>接下来是展示靶的损伤是如何产生的。</p><p>在Plot窗口中点击 Energy to Recoils,会有弹窗询问是关于Energy from Ions(离子中的能量)还是Energy absorbed by Silicon atoms(硅原子吸收的能量),任意选择一个即可(因为所有离子沉积的能量都被硅原子吸收了,对于单元素靶这两种图是相同的。如果靶中不止一种元素,而且想看到每一种元素吸收了多少能量时这个选项才是重要的)。</p><p>通过图像我们可以看出,转移给靶原子的能量在离子平均射程(约为2500A)之前几乎保持不变,随后它随着离子的停止迅速减小。其他的离子/靶组合情况可能与此非常不同。</p><p>有多少的能量转移给了级联反冲呢?<br>再次查看 %EnergyLoss选项框,我们可以将沉积到反冲原子中的能量累加起来: 24%+3%+29%=56%=106keV。因而离子直接地沉积了44%的能量给靶原子,而放弃了56%的能量给级联反冲原子。</p><p>打开图像:Damage Events。<br>一个包含了所有损伤细节的菜单会弹出。点击图像#1(Total Displacements),#2(TotalVacancies)和#3(Replacement Collisions)。然后点击:Show Plot Numbers 1 2 3。</p><p>顶部的曲线展示了 Total Target Displacements。这是被撞击出它们原本靶晶格中位置的原子数。接下来往下的一条曲线展示的是 Target Vacancies。这个相比靶错位曲线较低,表明空位数相比错位数较少。</p><p>最底部的曲线展示的是 Replacement Collisions。这些是入射原子失掉了几乎所有能量后不足以再继续往前走而进入反冲靶原子遗留下来的孔穴中所产生的错位。也就是说它撞击出来一个靶原子,然后在晶格中替代它。由于是相同的元素,结果在靶中没有变化。<br>正如你能看到的,较低的两条曲线的和等于较高的错位曲线。记得在级联反冲中的物理中展示的方程吗:<br>$$<br>错位=空位+复位碰撞<br>$$<br>在这个情形中,几乎10%的错位原子没有剩下空位,而是被另一个硅原子替代了。</p><hr><p>未完待续…<br>随缘更新了。</p>]]></content>
<summary type="html"><p>demo4 靶损伤计算</p></summary>
<category term="软件学习" scheme="http://paneersblog.github.io/categories/%E8%BD%AF%E4%BB%B6%E5%AD%A6%E4%B9%A0/"/>
<category term="SRIM" scheme="http://paneersblog.github.io/tags/SRIM/"/>
</entry>
<entry>
<title>win批处理语法</title>
<link href="http://paneersblog.github.io/52445.html"/>
<id>http://paneersblog.github.io/52445.html</id>
<published>2022-02-21T15:21:26.000Z</published>
<updated>2022-07-16T09:31:08.877Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>win批处理语法</p><span id="more"></span><h2 id="常用命令"><a href="#常用命令" class="headerlink" title="常用命令"></a>常用命令</h2><p><strong>%~dp0 [获取当前路径]</strong></p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">%~dp0 “d”为Drive的缩写,即为驱动器,磁盘、“p”为<span class="built_in">Path</span>缩写,即为路径,目录</span><br><span class="line"></span><br><span class="line"><span class="built_in">cd</span> %~dp0 :进入批处理所在目录</span><br><span class="line"></span><br><span class="line"><span class="built_in">cd</span> %~dp0bin\ :进入批处理所在目录的bin目录</span><br></pre></td></tr></table></figure><p><strong>%cd%[执行的路径]</strong><br>当前执行的路径,并非目标文件的路径</p><p><strong>taskkill /f /im notepad.exe [终止进程]</strong><br>taskkill /?打开帮助</p><p><strong>cmd窗口中文乱码</strong><br>在CMD窗口右键/默认值,打开属性选择 “默认代码页为简体中文GBK”</p><p><strong>获取命令帮助 xxx /?</strong><br>遇到记不清楚的命令,但记得名字,就可以键入 命令名 空格 /?就会有详细的该命令的帮助了,比如:ping /? cd /?</p><h2 id="一、基础语法"><a href="#一、基础语法" class="headerlink" title="一、基础语法"></a>一、基础语法</h2><ol><li><p>批处理文件是一个“.bat”结尾的文本文件,这个文件的每一行都是一条DOS命令。可以使用任何文本文件编辑工具创建和修改。</p></li><li><p>批处理是一种简单的程序,可以用 if 和 goto 来控制流程,也可以使用 for 循环。</p></li><li><p>批处理的编程能力远不如C语言等编程语言,也十分不规范。</p></li><li><p>每个编写好的批处理文件都相当于一个DOS的外部命令,把它所在的目录放到DOS搜索路径(path)中,即可在任意位置运行。</p></li><li><p>C:\AUTOEXEC.BAT 是每次系统启动时都会自动运行的,可以将每次启动时都要运行的命令放入该文件中。</p></li><li><p>大小写不敏感(命令符忽略大小写)</p></li><li><p>批处理的文件扩展名为 .bat 或 .cmd。</p></li><li><p>在命令提示下键入批处理文件的名称,或者双击该批处理文件,系统就会调用Cmd.exe来运行该文件。</p></li></ol><h2 id="二、参数"><a href="#二、参数" class="headerlink" title="二、参数"></a>二、参数</h2><h3 id="1-系统参数"><a href="#1-系统参数" class="headerlink" title="1.系统参数"></a>1.系统参数</h3><p><code>%SystemRoot% === C:\WINDOWS (%windir% 同样)</code></p><p><code>%ProgramFiles% === C:\Program Files</code></p><p><code>%USERPROFILE% === C:\Documents and Settings\Administrator (子目录有“桌面”,“开始菜单”,“收藏夹”等)</code></p><p><code>%APPDATA% === C:\Documents and Settings\Administrator\Application Data</code></p><p><code>%TEMP% === C:\DOCUME~1\ADMINI1~\LOCALS~1\Temp (%TEM% 同样)</code></p><p><code>%APPDATA% === C:\Documents and Settings\Administrator\Application Data</code></p><p><code>%OS% === Windows_NT (系统)</code></p><p><code>%Path% === %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem (原本的设置)</code></p><p><code>%HOMEDRIVE% === C: (系统盘)</code></p><p><code>%HOMEPATH% === \Documents and Settings\Administrator</code></p><p><code>:: 枚举当前的环境变量</code></p><p><code>setlocal enabledelayedexpansion</code></p><p><code>FOR /F "usebackq delims==" %%i IN (</code>set<code>) DO @echo %%i</code></p><h3 id="2-传递参数给批处理文件"><a href="#2-传递参数给批处理文件" class="headerlink" title="2.传递参数给批处理文件"></a>2.传递参数给批处理文件</h3><p>%[1-9]表示参数,参数是指在运行批处理文件时在文件名后加的以空格(或者Tab)分隔的字符串。</p><p>变量可以从%0到%9,%0表示批处理命令本身,其它参数字符串用 %1 到 %9 顺序表示。</p><p>举例如下(括号内容仅作为解释说明,运行时请删除):</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">call</span> test2.bat "hello" "haha" (执行同目录下的“test2.bat”文件,并输入两个参数)</span><br><span class="line"></span><br><span class="line">在“test2.bat”文件里写:</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %<span class="number">1</span> (打印: "hello")</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %<span class="number">2</span> (打印: "haha")</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %<span class="number">0</span> (打印: test2.bat)</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> %<span class="number">19</span> (打印: "hello"<span class="number">9</span>)</span><br></pre></td></tr></table></figure><h2 id="三、批处理基本命令"><a href="#三、批处理基本命令" class="headerlink" title="三、批处理基本命令"></a>三、批处理基本命令</h2><h3 id="0-help-命令"><a href="#0-help-命令" class="headerlink" title="0.help 命令"></a>0.help 命令</h3><p>语法: 命令 /?</p><p>可显示此命令的帮助信息</p><p>Sample:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">type</span> /? >>tmp.txt (把 <span class="built_in">type</span> 命令的帮助信息写入到tmp.txt文件里)</span><br><span class="line"></span><br><span class="line"><span class="built_in">help</span> <span class="built_in">type</span> (显示跟“<span class="built_in">type</span> /?”一样)</span><br></pre></td></tr></table></figure><h3 id="1-echo-命令"><a href="#1-echo-命令" class="headerlink" title="1.echo 命令"></a>1.echo 命令</h3><p>语法: echo [{on|off}] [message]</p><p>ECHO [ON | OFF] 打开回显或关闭回显功能。</p><p>ECHO 显示当前回显设置。</p><p>ECHO [message] 显示信息。</p><p>echo off 表示在此语句后所有运行的命令都不显示命令行本身;默认是on,on时会显示如: C:\文件夹路径>命令行。</p><p>在实际应用中我们会把这条命令和重定向符号( 也称为管道符号,详见DOS基础命令,一般用 > >> ^ )结合来实现输入一些命令到特定格式的文件中。</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> off</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> hello world (显示出“hello world”)</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> Windows Registry Editor Version <span class="number">5</span>.<span class="number">00</span> > c:\setupreg.reg (此前还没有 setupreg.reg 这个文件)</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> "SourcePath"="D:\\Win2003\\" >> c:\setupreg.reg (追加内容进 setupreg.reg 这个文件)</span><br></pre></td></tr></table></figure><h3 id="2-命令"><a href="#2-命令" class="headerlink" title="2.@ 命令"></a>2.@ 命令</h3><p>表示不显示@后面的命令,(在入侵过程中自然不能让对方看到你使用的命令啦 手动狗头)</p><p>@ 与 echo off 相象,但它是加在每个命令行的最前面,表示运行时不显示这一行的命令行(只能影响当前行)。</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off (此语句常用于开头,表示不显示所有的命令行信息,包括此句)</span><br><span class="line"></span><br><span class="line">@<span class="built_in">echo</span> please wait a minite...</span><br><span class="line"></span><br><span class="line">@<span class="built_in">format</span> X: /q/u/autoset</span><br></pre></td></tr></table></figure><p>(format 这个命令是不可以使用/y这个参数的,可喜的是微软留了个autoset这个参数给我们,效果和/y是一样的。)</p><h3 id="3-Goto-命令"><a href="#3-Goto-命令" class="headerlink" title="3.Goto 命令"></a>3.Goto 命令</h3><p>语法:goto label (label是参数,指定所要转向的批处理程序中的行。)</p><p>指定跳转到标签行,找到标签行后,程序将处理从下一行开始的命令。</p><p>label标签的名字可以随便起,但是最好是有意义的,字母前必须加个冒号“:”来表示这个字母是标签。</p><p>goto命令就是根据这个冒号来寻找下一步跳到到那里。经常与 if 配合使用,根据不同的条件来执行不同的命令组。</p><p>例子在下文的 5.Pause命令</p><h3 id="4-Rem-命令"><a href="#4-Rem-命令" class="headerlink" title="4.Rem 命令"></a>4.Rem 命令</h3><p>语法:Rem Message</p><p>(小技巧:用::代替rem)</p><p>注释命令,在C语言中相当与/<em>…</em>/,它并不会被执行,只是起一个注释的作用,便于别人阅读和自己日后修改。</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">@Rem Here is the description.</span></span><br></pre></td></tr></table></figure><h3 id="5-Pause-命令"><a href="#5-Pause-命令" class="headerlink" title="5.Pause 命令"></a>5.Pause 命令</h3><p>会暂停批处理的执行并在屏幕上显示Press any key to continue…的提示,等待用户按任意键后继续</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"></span><br><span class="line">:begin</span><br><span class="line"></span><br><span class="line"><span class="built_in">copy</span> a:*.* d:\back</span><br><span class="line"></span><br><span class="line"><span class="built_in">echo</span> Please put a new disk into driver A</span><br><span class="line"></span><br><span class="line"><span class="built_in">pause</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">goto</span> begin</span><br></pre></td></tr></table></figure><p>在这个例子中,驱动器 A中磁盘上的所有文件均复制到d:\back中。</p><p>显示的信息提示您将另一张磁盘放入驱动器 A 时,pause 命令会使程序挂起,以便您更换磁盘,然后按任意键再次复制。</p><h3 id="6-call-命令"><a href="#6-call-命令" class="headerlink" title="6.call 命令"></a>6.call 命令</h3><p>语法: call [[Drive:][Path] FileName [BatchParameters]] [:label [arguments]]</p><p>参数: [Drive:][Path] FileName 指定要调用的批处理程序的位置和名称。filename 参数必须具有 .bat 或 .cmd 扩展名。</p><p>调用另一个批处理程序,并且不终止父批处理程序。</p><p>如果不用call而直接调用别的批处理文件,那么执行完那个批处理文件后将无法返回当前文件并执行当前文件的后续命令。</p><p>call命令接受用作调用目标的标签。如果在脚本或批处理文件外使用 call,它将不会在命令行起作用。</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">call</span>="<span class="variable">%cd%</span>\test2.bat" haha kkk aaa (调用指定目录下的 test2.bat,且输入<span class="number">3</span>个参数给他)</span><br><span class="line"></span><br><span class="line"><span class="keyword">call</span> test2.bat arg1 arg2 (调用同目录下的 test2.bat,且输入<span class="number">2</span>个参数给他)</span><br></pre></td></tr></table></figure><blockquote><p>注:可以调用自身(死循环、递归)</p></blockquote><h3 id="7-start-命令"><a href="#7-start-命令" class="headerlink" title="7.start 命令"></a>7.start 命令</h3><p>调用外部程序,所有的 DOS命令和命令行程序都可以由 start命令来调用。</p><p>常用参数:</p><ol><li>MIN 开始时窗口最小化</li><li>SEPARATE 在分开的空间内开始 16 位 Windows 程序</li><li>HIGH 在 HIGH 优先级类别开始应用程序</li><li>REALTIME 在 REALTIME 优先级类别开始应用程序</li><li>WAIT 启动应用程序并等候它结束</li><li>parameters 这些为传送到命令/程序的参数</li></ol><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">start</span> /MIN test2.bat arg1 arg2 (调用同目录下的 test2.bat,且输入<span class="number">2</span>个参数给他,且本窗口最小化)</span><br><span class="line"><span class="function"></span></span><br><span class="line"><span class="function">e:\"<span class="title">program</span> <span class="title">files</span>"\列车时刻表\<span class="title">skb.exe</span> (文件路径名有空格时“ ”是必要的)</span></span><br></pre></td></tr></table></figure><h3 id="8-if-命令"><a href="#8-if-命令" class="headerlink" title="8.if 命令"></a>8.if 命令</h3><p>if 表示将判断是否符合规定的条件,从而决定执行不同的命令。有三种格式:</p><h4 id="1-if"><a href="#1-if" class="headerlink" title="1.if"></a>1.if</h4><p>语法: if [not] “参数” == “字符串” 待执行的命令</p><p>参数如果等于(not表示不等,下同)指定的字符串,则条件成立,运行命令,否则运行下一句。(注意是两个等号)</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> "%<span class="number">1</span>" == "a" <span class="built_in">format</span> a:</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> {%<span class="number">1</span>} == {} <span class="keyword">goto</span> noparms</span><br></pre></td></tr></table></figure><h4 id="2-if-exist"><a href="#2-if-exist" class="headerlink" title="2.if exist"></a>2.if exist</h4><p>语法: if [not] exist [路径]文件名 待执行的命令</p><p>如果有指定的文件,则条件成立,运行命令,否则运行下一句。</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="keyword">exist</span> config.sys edit config.sys (表示如果存在这文件,则编辑它,用很难看的系统编辑器)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> <span class="keyword">exist</span> config.sys <span class="built_in">type</span> config.sys (表示如果存在这文件,则显示它的内容)</span><br></pre></td></tr></table></figure><h4 id="3-if-errorlevel-number"><a href="#3-if-errorlevel-number" class="headerlink" title="3.if errorlevel number"></a>3.if errorlevel number</h4><p>语法: if [not] errorlevel <数字> 待执行的命令</p><p>如果程序返回值等于指定的数字,则条件成立,运行命令,否则运行下一句。(返回值必须按照从大到小的顺序排列)</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">@<span class="built_in">echo</span> off</span><br><span class="line"></span><br><span class="line"><span class="built_in">XCOPY</span> F:\test.bat D:\</span><br><span class="line"></span><br><span class="line"><span class="keyword">IF</span> <span class="keyword">ERRORLEVEL</span> <span class="number">1</span> (<span class="built_in">ECHO</span> 文件拷贝失败</span><br><span class="line"></span><br><span class="line">) <span class="keyword">Else</span> <span class="keyword">IF</span> <span class="keyword">ERRORLEVEL</span> <span class="number">0</span> <span class="built_in">ECHO</span> 成功拷贝文件</span><br><span class="line"></span><br><span class="line"><span class="built_in">pause</span></span><br></pre></td></tr></table></figure><blockquote><p>很多DOS程序在运行结束后会返回一个数字值用来表示程序运行的结果(或者状态),称为错误码errorlevel或称返回码。</p><p>常见的返回码为0、1。通过if errorlevel命令可以判断程序的返回值,根据不同的返回值来决定执行不同的命令。</p></blockquote><h4 id="4-else"><a href="#4-else" class="headerlink" title="4.else"></a>4.else</h4><p>语法: if 条件 (成立时执行的命令) else (不成立时执行的命令)</p><p>如果是多个条件,建议适当使用括号把各条件包起来,以免出错。</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="number">1</span> == <span class="number">0</span> ( <span class="built_in">echo</span> comment1 ) <span class="keyword">else</span> <span class="keyword">if</span> <span class="number">1</span>==<span class="number">0</span> ( <span class="built_in">echo</span> comment2 ) <span class="keyword">else</span> (<span class="built_in">echo</span> comment3 )</span><br></pre></td></tr></table></figure><blockquote><p>注:如果 else的语句需要换行,if执行的行尾需用“^”连接,并且 if执行的动作需用(括起来),否则报错</p></blockquote><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="number">1</span> == <span class="number">0</span> ( <span class="built_in">echo</span> comment1 ) <span class="keyword">else</span> <span class="keyword">if</span> <span class="number">1</span>==<span class="number">0</span> ( <span class="built_in">echo</span> comment2 ) ^</span><br><span class="line"><span class="keyword">else</span> (<span class="built_in">echo</span> comment3 )</span><br></pre></td></tr></table></figure><h4 id="5-比较运算符"><a href="#5-比较运算符" class="headerlink" title="5.比较运算符"></a>5.比较运算符</h4><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">EQU</span> - 等于 (一般使用“==”)</span><br><span class="line"></span><br><span class="line"><span class="keyword">NEQ</span> - 不等于 (没有 “!=”,改用“ <span class="keyword">if</span> <span class="keyword">not</span> <span class="number">1</span>==<span class="number">1</span> ”的写法)</span><br><span class="line"></span><br><span class="line"><span class="keyword">LSS</span> - 小于</span><br><span class="line"></span><br><span class="line"><span class="keyword">LEQ</span> - 小于或等于</span><br><span class="line"></span><br><span class="line"><span class="keyword">GTR</span> - 大于</span><br><span class="line"></span><br><span class="line"><span class="keyword">GEQ</span> - 大于或等于</span><br></pre></td></tr></table></figure><h3 id="9-choice-命令"><a href="#9-choice-命令" class="headerlink" title="9.choice 命令"></a>9.choice 命令</h3><p>choice 使用此命令可以让用户输入一个字符(用于选择),从而根据用户的选择返回不同的 errorlevel,</p><p>然后配合 if errorlevel 选择运行不同的命令。</p><blockquote><p>注意:choice命令为DOS或者Windows系统提供的外部命令,不同版本的choice命令语法会稍有不同,请用choice /?查看用法。</p></blockquote><p>choice 使用此命令可以让用户输入一个字符,从而运行不同的命令。</p><p>使用时应该加/c:参数,c:后应写提示可输入的字符,之间无空格。它的返回码为1234……</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">choice /c:dme defrag,mem,end</span><br></pre></td></tr></table></figure><p>将显示:</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">defrag,mem,end[D,M,E]?</span><br></pre></td></tr></table></figure><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">choice /c:dme defrag,mem,end</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> <span class="keyword">errorlevel</span> <span class="number">3</span> <span class="keyword">goto</span> defrag (应先判断数值最高的错误码)</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> <span class="keyword">errorlevel</span> <span class="number">2</span> <span class="keyword">goto</span> mem</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> errotlevel <span class="number">1</span> <span class="keyword">goto</span> end</span><br></pre></td></tr></table></figure><h3 id="10-for-命令"><a href="#10-for-命令" class="headerlink" title="10.for 命令"></a>10.for 命令</h3><p>for 命令是一个比较复杂的命令,主要用于参数在指定的范围内循环执行命令。</p><ol><li>语法结构</li></ol><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">`<span class="keyword">for</span> {%variable | <span class="variable">%%v</span>ariable} <span class="keyword">in</span> (<span class="built_in">set</span>) <span class="keyword">do</span> command [command-parameters]` </span><br></pre></td></tr></table></figure><pre><code>%variable 指定一个单一字母可替换的参数。变量名称是区分大小写的,所以 %i 不同于 %I 在批处理文件中使用 FOR 命令时,指定变量建议用 %%variable而不要用 %variable。 (set) 指定一个或一组文件。可以使用通配符。command 指定对每个文件执行的命令。 command-parameters 为特定命令指定参数或命令行开关。</code></pre><ol><li><p>如果命令扩展名被启用,下列额外的 FOR 命令格式会受到支持:</p><p> 1.FOR /D %variable IN (set) DO command [command-parameters]<br> 如果集里面包含通配符,则指定与目录名匹配,而不与文件名匹配。</p><p> 2.FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]<br> 检查以 [drive:]path 为根的目录树,指向每个目录中的FOR 语句。<br> 如果在 /R 后没有指定目录,则使用当前目录。如果集仅为一个单点(.)字符,则枚举该目录树。</p><p> 3.FOR /L %variable IN (start,step,end) DO command [command-parameters]<br> 该集表示以增量形式从开始到结束的一个数字序列。</p><p> 如:(1,1,5) 将产生序列 1 2 3 4 5; 而(5,-1,1) 将产生序列 (5 4 3 2 1)。</p><p> 4.有或者没有 usebackq 选项:</p><p> FOR /F [“options”] %variable IN (file-set) DO command</p><p> FOR /F [“options”] %variable IN (“string”) DO command</p><p> FOR /F [“options”] %variable IN (command) DO command</p><p> 参数”options”为:</p><p> eol=c - 指一个行注释字符的结尾(就一个,如“;”)</p><p> skip=n - 指在文件开始时忽略的行数。</p><p> delims=xxx - 指分隔符集。这个替换了空格和跳格键的默认分隔符集。</p><p> tokens=x,y,m-n - 指每行的哪一个符号被传递到每个迭代的 for 本身。这会导致额外变量名称的分配。</p><p> m-n格式为一个范围。通过 nth 符号指定 mth。</p><p> 如果符号字符串中的最后一个字符星号,那么额外的变量将在最后一个符号解析之后分配并接受行的保留文本。</p><p> usebackq - 指定新语法已在下类情况中使用:</p><p> 在作为命令执行一个后引号的字符串并且一个单引号字符为文字字符串命令并允许在 filenameset中使用双引号扩起文件名称。</p></li><li><p>Sample:</p></li></ol><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line">:: 如下命令行会显示当前目录下所有以bat或者txt为扩展名的文件名。</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> <span class="variable">%%c</span> <span class="keyword">in</span> (*.bat *.txt) <span class="keyword">do</span> (<span class="built_in">echo</span> <span class="variable">%%c</span>)</span><br><span class="line"></span><br><span class="line">::如下命令行会显示当前目录下所有包含有 e 或者 i 的目录名。</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /D <span class="variable">%%a</span> <span class="keyword">in</span> (*e* *i*) <span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">%%a</span></span><br><span class="line"></span><br><span class="line">:: 如下命令行会显示 E盘test目录 下所有以bat或者txt为扩展名的文件名。</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /R E:\test <span class="variable">%%b</span> <span class="keyword">in</span> (*.txt *.bat) <span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">%%b</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /r <span class="variable">%%c</span> <span class="keyword">in</span> (*) <span class="keyword">do</span> (<span class="built_in">echo</span> <span class="variable">%%c</span>) :: 遍历当前目录下所有文件</span><br><span class="line"></span><br><span class="line">:: 如下命令行将产生序列 <span class="number">1</span> <span class="number">2</span> <span class="number">3</span> <span class="number">4</span> <span class="number">5</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /L <span class="variable">%%c</span> <span class="keyword">in</span> (<span class="number">1</span>,<span class="number">1</span>,<span class="number">5</span>) <span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">%%c</span></span><br><span class="line"></span><br><span class="line">:: 以下两句,显示当前的年月日和时间</span><br><span class="line"></span><br><span class="line"><span class="keyword">For</span> /f "tokens=<span class="number">1</span>-<span class="number">3</span> delims=-/. " <span class="variable">%%j</span> <span class="keyword">In</span> ('<span class="built_in">Date</span> /T') <span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">%%j</span>年<span class="variable">%%k</span>月<span class="variable">%%l</span>日</span><br><span class="line"></span><br><span class="line"><span class="keyword">For</span> /f "tokens=<span class="number">1</span>,<span class="number">2</span> delims=: " <span class="variable">%%j</span> <span class="keyword">In</span> ('<span class="built_in">TIME</span> /T') <span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">%%j</span>时<span class="variable">%%k</span>分</span><br><span class="line"></span><br><span class="line">:: 把记事本中的内容每一行前面去掉<span class="number">8</span>个字符</span><br><span class="line"></span><br><span class="line"><span class="built_in">setlocal</span> enabledelayedexpansion</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /f <span class="variable">%%i</span> <span class="keyword">in</span> (zhidian.txt) <span class="keyword">do</span> (</span><br><span class="line"></span><br><span class="line"><span class="built_in">set</span> atmp=<span class="variable">%%i</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">set</span> atmp=<span class="variable">!atmp:~8!</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> {<span class="variable">!atmp!</span>}=={} ( <span class="built_in">echo</span>.) <span class="keyword">else</span> <span class="built_in">echo</span> <span class="variable">!atmp!</span></span><br><span class="line"></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">:: 读取记事本里的内容(使用 delims 是为了把一行显示全,否则会以空格为分隔符)</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /f "delims=" <span class="variable">%%a</span> <span class="keyword">in</span> (zhidian.txt) <span class="keyword">do</span> <span class="built_in">echo</span>.<span class="variable">%%a</span></span><br></pre></td></tr></table></figure><ol start="4"><li><p>continue 和 break</p><p> 利用 goto 实现程序中常用的 continue 和 break 命令, 其实非常简单</p><blockquote><p>continue: 在 for 循环的最后一行写上一个标签,跳转到这位置即可 </p><p>break: 在 for 循环的外面的下一句写上一个标签,跳转到这位置即可</p></blockquote><p> Sample: (伪代码)</p> <figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> /F ["options"] %variable <span class="keyword">IN</span> (command) <span class="keyword">DO</span> (</span><br><span class="line"></span><br><span class="line">... <span class="keyword">do</span> command ...</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ... <span class="keyword">goto</span> continue</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span> ... <span class="keyword">goto</span> <span class="built_in">break</span></span><br><span class="line"></span><br><span class="line">... <span class="keyword">do</span> command ...</span><br><span class="line"></span><br><span class="line">:continue</span><br><span class="line"></span><br><span class="line">)</span><br><span class="line"></span><br><span class="line">:<span class="built_in">break</span></span><br></pre></td></tr></table></figure></li></ol><h2 id="四、其他命令"><a href="#四、其他命令" class="headerlink" title="四、其他命令"></a>四、其他命令</h2><h3 id="1-ping命令"><a href="#1-ping命令" class="headerlink" title="1.ping命令"></a>1.ping命令</h3><p>测试网络联接状况以及信息包发送和接收状况。但是不能够测试端口。</p><p>语法:ping IP地址或主机名 [-t] [-a] [-n count] [-l size]</p><blockquote><p>参数含义:</p><p>-t 不停地向目标主机发送数据;</p><p>-a 以IP地址格式来显示目标主机的网络地址;</p><p>-n count 指定要Ping多少次,具体次数由count来指定;</p><p>-l size 指定发送到目标主机的数据包的大小。</p></blockquote><p>Sample:</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">ping</span> <span class="number">192</span>.<span class="number">168</span>.<span class="number">0</span>.<span class="number">1</span> -t (不停的测试<span class="number">192</span>.<span class="number">168</span>.<span class="number">0</span>.<span class="number">1</span>,按ctrl+c停止)</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> /L <span class="variable">%%a</span> <span class="keyword">in</span> (<span class="number">0</span>,<span class="number">1</span>,<span class="number">255</span>) <span class="keyword">do</span> <span class="built_in">ping</span> <span class="number">192</span>.<span class="number">168</span>.<span class="number">0</span>.<span class="variable">%%a</span> -n <span class="number">1</span> >> tmp.txt (<span class="built_in">ping</span>一下所有的局域网电脑)</span><br></pre></td></tr></table></figure><h3 id="2-telnet-命令"><a href="#2-telnet-命令" class="headerlink" title="2.telnet 命令"></a>2.telnet 命令</h3><p>测试端口使用 telnet IP地址或主机名 端口,使用tcp协议的</p><p>Sample:</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">telnet <span class="number">192</span>.<span class="number">168</span>.<span class="number">0</span>.<span class="number">1</span> <span class="number">80</span> (测试<span class="number">192</span>.<span class="number">168</span>.<span class="number">0</span>.<span class="number">1</span>的<span class="number">80</span>端口)</span><br></pre></td></tr></table></figure><h3 id="3-color-命令"><a href="#3-color-命令" class="headerlink" title="3.color 命令"></a>3.color 命令</h3><p>设置背景及字体颜色</p><p>语法: color bf</p><blockquote><p>b 是指定背景色的十六进制数字</p><p>f 指定前景颜色(即字体颜色)。</p></blockquote><p>颜色值: </p><table><thead><tr><th>0:黑色</th><th>1:蓝色</th><th>2:绿色</th><th>3:湖蓝</th><th>4:红色</th><th>5:紫色</th><th>6:黄色</th><th>7:白色</th></tr></thead><tbody><tr><td>8:灰色</td><td>9:淡蓝</td><td>A:淡绿</td><td>B:浅绿</td><td>C:淡红</td><td>D:淡紫</td><td>E:淡黄</td><td>F:亮白</td></tr></tbody></table><p>如果没有给定任何参数,该命令会将颜色还原到 CMD.EXE 启动时的颜色。</p><p>如果两参数一样,视为无效输入。只有一个参数时,设置字体。</p><h3 id="4-random-命令"><a href="#4-random-命令" class="headerlink" title="4.random 命令"></a>4.random 命令</h3><p>产生随机数(正整数0~)</p><h3 id="5-exit-命令"><a href="#5-exit-命令" class="headerlink" title="5.exit 命令"></a>5.exit 命令</h3><p>结束程序。即时是被调用的程序,结束后也不会返回原程序</p><h3 id="6-hutdown命令"><a href="#6-hutdown命令" class="headerlink" title="6.hutdown命令"></a>6.hutdown命令</h3><p>shutdown -s 关机</p><h2 id="五、文件处理"><a href="#五、文件处理" class="headerlink" title="五、文件处理"></a>五、文件处理</h2><h3 id="1-删除"><a href="#1-删除" class="headerlink" title="1.删除"></a>1.删除</h3><p>1.删除一个文件或多个文件</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">del</span> /s /q /f d:\test\a.bat</span><br></pre></td></tr></table></figure><p>将直接删除d:\test\a.bat,没有任务提示</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">del</span> temp\* /q /f /s</span><br></pre></td></tr></table></figure><p>将直接删除 本目录的 temp 目录的所有文件,没有任务提示</p><p>删除文件的时候可以使用“*”作通配符</p><p>2.删除一个空目录</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">rd</span> /q /s d:\test\log</span><br></pre></td></tr></table></figure><p>将直接删除d:\test\log目录,如果log目录里面有文件将无法删除</p><p>3.删除一个非空目录 (必须指定目录名称)</p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">rmdir</span> /q /s d:\test\logs</span><br></pre></td></tr></table></figure><p>必须指定目录名称,不能使用通配符</p><p>/S 除目录本身外,还将删除指定目录下的所有子目录</p><p>/Q 安静模式,带 /S 删除目录树时不要求确认</p><p>无论里面是否有文件或文件夹将全部直接删除</p><h3 id="2-创建目录"><a href="#2-创建目录" class="headerlink" title="2.创建目录"></a>2.创建目录</h3><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">MKDIR</span> [drive:]<span class="built_in">path</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">MD</span> [drive:]<span class="built_in">path</span></span><br></pre></td></tr></table></figure><p>路径有空格时,可以用双引号括起来,也可以用 <code>&nbsp;</code> 替代</p><hr><p>就这样吧 有想法再说</p><blockquote><p><a href="https://blog.csdn.net/qq_36838191/article/details/83046599?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522164543495616780366548228%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=164543495616780366548228&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~top_positive~default-1-83046599.first_rank_v2_pc_rank_v29&utm_term=bat&spm=1018.2226.3001.4187">参考</a></p></blockquote><hr>]]></content>
<summary type="html"><p>win批处理语法</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="DOS" scheme="http://paneersblog.github.io/tags/DOS/"/>
</entry>
<entry>
<title>SRIM入门(三)</title>
<link href="http://paneersblog.github.io/31090.html"/>
<id>http://paneersblog.github.io/31090.html</id>
<published>2022-02-19T16:00:42.000Z</published>
<updated>2022-07-16T09:31:27.677Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>demo3 复合靶的创建</p><span id="more"></span><p>前文已经描述了如何设置TRIM,如何确定一个n型半导体井的注入离子种类、能量以及如何估算在半导体注入过程中的损伤。此demo将描述创建一个气体固体复合结构的载能离子气体电离探测器。</p><p>设定一个装置,由一个长的圆柱体构成。在其左边有一个非常狭窄的入射窗口,它由一种名为 Paralence “C”的聚合物制成,仅为 1um的薄膜。它能够让束流进入探测器时损失最少的能量。这个探测器内部充有名为 P-10的气体,其成分为 10%甲烷和 90%氩气。氩气原子被粒子电离,然后放出的电子被电场清除出去。<br>有一种可能是电离气体流会导致击穿,并且 10%的甲烷气体会“猝息”过多的电荷堆积。最后在末端有一个“束流截止”靶。束流需要全部被截止在 P-10气体中,通常会使用一个足够厚的尾部平板以确保安全。</p><p>我们在 SRIM中创建这个探测器,来用作创建复合靶的例子。通过 SRIM我们可以估计当一个束流进入探测器时会发生什么。</p><p>首先我们打开 SRIM,选择 TRIM Calculation,打开 TRIM Demo,在第二列底部选择靶”He(5MeV)into Gas Ionization Detector”,然后点击 Save Input and Statr TRIM开始计算(或许会有一个弹窗,是关于靶密度的提醒,点击 Yes即可)。</p><p>这样设置可以提供给我们气体电离探测器的靶细节信息。</p><blockquote><p>另外有几点需要注意:</p><ul><li>所有的离子在到达底部的束流截止靶前应停止下来</li><li>我们得到的图像只展示了靶的一部分。注意横坐标,显示的距离为 40nm到 50nm处的深度。也就是说是将该深度的部分进行了放大,这使得我们可以更详细的看到离子最终的径迹</li><li>狭窄的入射窗口没有画出,但实际上是存在的。当我们将所选区域放大时它所在的第一层就不显示在图中了。</li></ul></blockquote><p>此时我们可以查看几张计算得到的图像,但是我们看不到反冲原子或是溅射原子。这是因为他们在这个计算中被忽略了。 </p><p>接下来我们要手动建立一个相同的设置来展示如何在 TRIM中创建一个复合靶。<br>首先关闭计算窗口,弹窗点否。 </p><ol><li>点击 Clear All清空所有条目 </li><li>输入离子信息(ION DATA)<ol><li>在 Ion Data中输入氦</li><li>输入离子能量(以5MeV为例)</li><li>入射角度垂直,故保持不变</li></ol></li><li>输入靶信息(分为三层:表面薄膜、长圆柱气体以及黄铜束流截止靶)<ol><li>首先是Paralence “C”薄膜。用快捷的方式输入它。<ol><li>在 TARGET DATA右边有 Compound Dictionary按钮,点击它。</li><li>此时我们会得到300多种混合物,Paralence “C”是一种商品名称,我们要知道它的确切名字或者查阅冗长的商品名称列表来寻找它。</li><li>点击 PLASTICS/POLYMERS,在展开的列表中我们可以找到“Polychloro-p-xylyene/Paralene-C”。此时我们会得到关于他的一些信息。点击Paralene-C,然后点击 Add to Current Layer,会有弹窗提示是否使用该化合物的阻止本领修正,选择是就对了</li></ol></li><li>此时第一层已经OK了,对于其厚度(width,默认为10000Ang),10000A=1um,故不需改动,可以创建第二层了</li><li>点击 Add New Layer,键入该层的名字如:P-10 Gas。然后在右侧通过点击 PT来添加Ar和CH<sub>4</sub>。<ol><li>Ar作为单质可以直接添加,CH<sub>4</sub>要分别添加 C和 H。</li><li>现在我们来设置每种元素的数量。已知90%的Ar和10%的CH<sub>4</sub>,这是质量百分比,在 SRIM中使用原子百分比。可通过相对原子数,分别在Ar、H、C的 Atom.Stoich.列中输入64、29、7(具体计算不展开了,很简单),然后SRIM会自动将其归一化为正确的比例。</li><li>另外,在该层旁边要勾选“Gas”,然后将密度修改为气体密度,0.00125</li><li>最后将该层的厚度改为 49mm</li></ol></li><li>新建束流截止靶,层名字尽量简洁,可用:Brass<ol><li>为了简化输入,可仍使用 Compound Dictionary按钮,点击METAL/ALLOYS</li><li>找到 Brass(typical),点击它然后点击 Add New Element to Layer,弹窗点 是</li><li>黄铜中包换铜、锌和铅。除了层厚,所有的数据都已经填好了。我们将厚度设置为 2.5mm,记得下拉单位菜单选择“mm”</li></ol></li></ol></li></ol><p>这就完成了计算的设定。<br>注意到我们没有像在之前(demo2)一样在窗口的顶部改变计算类型(“Type of TRIM Calculation”)。<br>我们想要看在运行计算程序时将会发生什么,所以现在我们在使用快速损伤计算(默认)。特别是我们并不确定是否设定了足够厚的气体靶来截止所有的离子,我们将运行TRIM来看看将发生什么然后调整尺寸。</p><p>点击 Save Input and Run TRIM开始计算</p><p>如果输入信息无误的话,我们将会得到粒子运动的轨迹图像,我们可以通过修改计算来得到更多更详细的信息。</p><ol><li>在 TRIM窗口点击 PAUSE</li><li>点击 Change TRIM</li><li>此时我们想要查看离子射程末尾的细节。</li><li>展开图像窗口。在左边你可以看到一个名为 PLOT Window 的表格。</li><li>在其下方是数字 0A-515010000A。这意味着这个图像显示了从表面 0 埃到 51.5mm 最深处的整个靶的情况。改变左窗口的值为40mm=400000000A(8个零)。改变右窗口的值为50mm=500000000A(8个零)。这将会产生一个专门显示射程末端的窗口。</li><li>在窗口的顶部点击 End Edit键。</li><li>将会有一个弹窗告诉你你将重新开始 TRIM计算。点击Yes继续,TRIM将重新启动。</li></ol><p>这时你的图像应该和你执行 DEMO 所得到的相同。 </p><p>注意到离子在它们行程的末尾之前都具有很好的方向性。它们初始速度很大,使得它们无法与靶发生强相互作用。靶中的传导电子具有相当于每核子25keV的速度(氦离子的速度大约为100keV,因为氦离子具有4个原子质量单位)。<br>这是在氦和靶电子之间发生最大强度相互作用的能量。氦和靶核之间的相互作用只有在这个能量以下才是显著的。<br>因而直到氦离子能量降到 100keV,也就是初始能量 5MeV的2%以下前,氦离子束一直被紧紧地聚焦着。</p><p>接下来看几张图。点击 Pause TRIM</p><ul><li>点击Ion Distribution。 <ul><li>你将会看到一个漂亮的高斯分布,中心位于 46.6mm 处。它非常窄,歧离度不到深度的2%。</li></ul></li><li>点击 Ionization。<ul><li>这张图展示了耗散到靶电子中去的能量。注意到在图像的底部是非常小的反冲原子电离的贡献(蓝线)。超过 99%转移给电子的能量损失是通过和离子的直接作用发生的。</li></ul></li><li>点击 Phonons。<ul><li>这个图像恰好显示了与靶中产生声子相反的趋势。现在靶中反冲原子占据了能量损失的主要成分。注意坐标的单位,声子能损大约是由于靶电子发生的离子能损的 1%。</li><li>事实上,反冲原子给靶电子的贡献和声子(损失给靶原子)大致相当。离子损失给声子的能量几乎为零(看图中灰暗的红色虚线)。我们可以查看窗口右面叫做((%ELOSS的表格,这里可以看到能量损失的相对分布。直接损失给靶电子的能量大约是离子能量损失的 99%,而其他的损失则是相当微小的。</li></ul></li></ul><hr><p> <em><strong>TRIM设置窗口的tips:</strong></em></p><p>在左下角有一个带有输入框的命令“AutoSave at Ion#”。<br>在一定数量的离子后 TRIM会自动保存计算结果。当我们通宵运行 TRIM时,这个特色工具确保了即使出现断电情形也会有信息被存储下来。默认值是10000个离子。你可以使用 Resume Saved TRIM命令来查看已经计算好的结果。</p><p>下一个命令是 Total Number of Ions(默认为 99999)。<br>若使用略有不同的离子或靶得到相同的计算结果,这一命令在对它们进行比较时非常有用。但所有设定的离子计算完成时,它会保存计算结果并停止。</p><p>下一个命令是随机数产生器(默认为空白)。<br>它用于计算人工制造的事件(奇异事件)。例如,也许在 10000 个离子中可能只有一次机会使某个离子能够和表面原子发生强烈的碰撞,产生一个强级联反冲。如果你想保存典型的图像,有时这些罕见的事件会产生不正常的图像造成干扰。输入任意数字(1就可以)然后你将得到一个完全不同的计算结果。如果没有数字被键入,那么这个默认的数值是16381,它是深入钻研随机数理论的人所崇敬的一个数字(我也不是很懂)。</p><hr><p>更新预告:靶损伤计算</p><hr>]]></content>
<summary type="html"><p>demo3 复合靶的创建</p></summary>
<category term="软件学习" scheme="http://paneersblog.github.io/categories/%E8%BD%AF%E4%BB%B6%E5%AD%A6%E4%B9%A0/"/>
<category term="SRIM" scheme="http://paneersblog.github.io/tags/SRIM/"/>
</entry>
<entry>
<title>SRIM入门(二)</title>
<link href="http://paneersblog.github.io/19550.html"/>
<id>http://paneersblog.github.io/19550.html</id>
<published>2022-02-16T15:29:36.000Z</published>
<updated>2022-07-16T09:32:44.885Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>demo2 靶的混合和溅射</p><span id="more"></span><p>demo1主要介绍了如何设置TRIM,如何确定一个n型井的注入离子和能量以及如何估算在注入过程中的损伤。此demo2将介绍其他粒子与固体的相互作用。</p><h3 id="界面混合和溅射"><a href="#界面混合和溅射" class="headerlink" title="界面混合和溅射"></a>界面混合和溅射</h3><p><strong>界面混合</strong>是原子从一层靶被输运到另一层靶的过程。<br>通常这是不希望产生的效应。我们已经看到了离子如何将大量的能量转移给反冲原子并使其移动很长的距离,产生显著的级联碰撞。当一个反冲原子穿过一个靶层进入另一个时,该靶层就被污染了。 </p><p>然而有一些特例是特意应用反冲混合进行材料改性,这个过程被叫做“反冲注入”。这个技术用于一些操作起来很难或者具有危险性的材料的注入,例如包含放射性物质材料的合成。<br>例如将很薄的一层钙沉积在硅靶上,然后将其放置在一个核反应堆中使钙转化成射性同位素。之后硅靶被放置在离子注入机中并将大剂量的氙(Xe)注入到钙层中去。氙离子就会将一些放射性物质撞击到硅靶中去并使其停留于其中。在移除所有剩余在表面的钙原子后,含有放射性钙的硅靶就可以被安全地处理了。若需要提供一个能释放出放射性离子(此处来自于钙原子)而危险性又远低于纯的放射性钙靶的样品,这样的一个靶是很合适的。</p><p><strong>溅射</strong>是和反冲注入相反的一个过程。<br>表面原子通过产生的级联反冲往回冲出靶,并具有足够的能量能够离开靶并脱离靶表面。表面会施加给原子一种结合力,即所谓表面结合能E<sub>surf</sub>。由于靶表面的原子并不是在一个面上被束缚住的,因而要使它从其晶格中移位所需的能量比它在固体内部被其他原子围绕时要小。一个表面原子所受到的电子约束更小。对固体而言,E<sub>surf</sub>通常小于移位能E<sub>disp</sub>。</p><p>此时我们可以借助TRIM中自带的demo来进行更好的理解。<br>接下来我们以其中几个例子来讲述靶混合与靶溅射。</p><blockquote><ul><li>打开SRIM软件 </li><li>进入TRIM Calation 窗口 </li><li>点击位于界面左上角的 TRIM DEMO</li><li>此时你会看到12个示例的设置,他们展示了在不同的应用中 TRIM 可以如何被使用。</li><li>我们以 Xe into Si/Pt/Si(Mixing a Marker) 为例,点击它查看各种输入参数 </li><li>点击 Save Input and Run TRIM,程序就会立刻开始计算</li></ul></blockquote><h3 id="靶混合"><a href="#靶混合" class="headerlink" title="靶混合"></a>靶混合</h3><p>上述例子展示了在硅靶中间的一个铂的薄层,它用来展示相互混合效应能够有多大。</p><p>点击选择图像:Ion/Recoil Distribution。<br>在弹出的子菜单中选择“ 2-SiliconRecoil Distribution”和4-Silicon Recoil Distribution”,然后点击Plot。<br>这两类反冲硅原子的分布将会用两种不同颜色绘制以区分。</p><p>就在不到100个离子入射之后,含有铂的空隙就开始被硅原子填充了。在进行到 400 个原子时,这个层将会有接近5%的硅原子。对于如氙(原子序数为54)这样的重离子,原子向这个层中的转移的效率将会很高。</p><p>现在我们关闭这个图像窗口,点击图像:Ion/Recoil Distribution。<br>在弹出的子菜单中选择3-PlatinumRecoilDistribution,然后点击Plot。</p><p>这个图像展示了铂层中的原子,以及其中的多少已经进入了硅中。尤其值得注意的是朝着表面移位的铂原子数非常大,比例达 50%,和被驱使深入到靶中的铂原子数相当。 </p><p><strong>这是非常值得注意的!</strong><br>离子都在进入深入靶中的方向,并且所有的初始反冲粒子一般也是朝着与入射粒子相同的方向,也就是深入靶中。可是最后原子为何能停留在比它们开始时更接近表面的位置呢?</p><p>为了得到其中缘由,点击 XY Longitudinal 图像来展示每个离子以及它造成的移位(这个图像在CollisionPlots部分)<br>在这个图像的底部有一个标记为 -Clear 的按键。这将会清除图像使得你可以看到单个粒子和它产生的级联反冲。离子径迹是一条稀疏的红色点状线,所有的级联反冲都由此开始。<br>每个级联反冲(不是离子的级联反冲)开始都是朝着向前的方向,但是随后其方向很快变为向各个方向随机分布。<br>稠密的级联反冲的轨迹看上去分布于没有特定取向的绿色球状空间中级联反冲牵涉到如此多的粒子,(其中包含的信息量如此之大)以至于任何初始离子方向的信息都迅速被丢失了。<br>这个级联反冲变成了各向同性的事件,即原子会朝一个方向运动的概率大致相当(注意:对于不同性能的电脑,可能需要按下“Clear”键后再在TRIM 窗口的顶部按下“Pause”,然后会在下一个离子进入后停止展示)</p><p>这就是使铂原子朝着表面移动的原因。<br>这些大的级联反冲会迅速失去原有的前进方向方向而变得具有向各个方向运动的可能。其发生的程度大小可以用被向前散射并深入到硅靶中的铂原子数和朝表面散射的铂原子数的差分来衡量。</p><p>第二个需要注意的问题是铂原子移动的距离很长。初始的铂原子层厚度为30埃。使用不超过500个入射粒子进行模拟,你将能够看到有铂原子被推出30埃的铂原子层以外。</p><p>此时我们可以去到TRIM DISTRIBUTIONS 选项框然后点击 File 选择 Ion/Recoil Distributions命令,我们将会得到一张数据表格,它比图像展示了更多的细节。这个文件被放置在SRIM文件夹下的SRIMOutputs中,并被命名为RANGE.txt。<br>其数据显示,一些铂原子到达深入表面 100 埃的位置,而其他部分原子已经到达了靶的背面。<br>反冲效率如此之高,以至于在使用不到500个入射粒子时已经有铂原子移位并穿过了硅靶。如果 TRIM 再使用几千个离子进行模拟,一些铂原子将会穿出靶的背面并与靶分离。</p><blockquote><p>为了理解下文即将提到的靶溅射,我们应让程序继续计算,至少有1000个离子模拟完成。</p></blockquote><h3 id="靶溅射"><a href="#靶溅射" class="headerlink" title="靶溅射"></a>靶溅射</h3><p>溅射是指近表面原子从靶中脱离的现象。<br>当一个级联反冲给靶原子一个大于其表面结合能的能量时,原子可能会被溅射。而实际上要发生溅射时,原子穿过表面时它垂直于表面方向的动能必须大于表面结合能。表面溅射以溅射率描述,其定义为每个入射粒子所能溅射出的平均靶原子数。如果靶由若干种元素组成,每种元素都溅射率具有相应的溅射率。<br>$$<br>溅射率=溅射出的原子数/入射粒子数<br>$$<br>特定种类的原子的表面结合能(SBE)目前只对于几种材料是已知的,但通常可以使用升华热来进行估计。<br>典型值是:镍Ni(4.46eV)、铜Cu(3.52eV)、钯Pd(3.91eV)、银Ag(2.97eV)、铂Pt(5.86eV)和金Au(3.80eV)。当你设置 TRIM计算时这些值将会被提示。</p><blockquote><p>关于溅射我们应了解:</p><ul><li>对于溅射而言,只有朝向靶表面的级联反冲是重要的。因而通常只使用单个薄靶来模拟溅射就足够了。<br>以相对原子质量超过20的重离子为例,通常一个厚为300埃的靶就足够了。使用非常薄的靶可以减少用于计算对溅射无贡献的级联反冲的时间。对于像氦这样的轻离子,由于离子可以在靶的深层产生背散射并造成表面的溅射,使用较厚(比如1000 埃)的靶,就十分必要。<br>一次计算所需要的靶深度可以通过运行几个快速的情形进行估算,即采用变化厚度的靶进行计算,然后看看在哪个厚度溅射率趋向于常值。</li><li>溅射率对表面结合能(SBE)(而表面结合能是需要输入的一个计算参数)非常敏感。<br>注意,对于真实的表面,这个能量随着离子轰击会由于表面粗糙度、损伤以及化合物的表面化学计量的变化而变化。溅射率对表面结合能的敏感度可以在计算时通过使用图像菜单来展现。溅射率对SBE图像可以精确到大约30%。</li><li>对于低能离子入射情况下靶中的级联反冲(溅射的一个主要贡献),TRIM 为计算散射 , 采 用 了 以 下 文 献 中 的 硬 球 模 型 : J.P.Biersackand W. Eckstein,Appl.Phys.,A34,73-94(1984)</li></ul></blockquote><p>一些离开靶的级联反冲原子可能是从比表面区域更深的靶内部出来。<br>我们能够发现,一些铂原子是从超过200埃深的靶内部碰撞后溅射出来的。现在看着 TRIM 窗口右边名为 SPUTTERING YIELD(SY) 的部分。这给出了每个入射粒子溅射出的原子数。其显示每个入射粒子会溅射出大约6或7个硅原子。</p><p>事实上这些离子正在产生一个洞,因为更多的原子在离开而不是到达,其比例达 6:1!进一步说,如果计算使用超过1000个离子,你将会看到甚至会有一定数量的铂原子溅射出来。<br>给出的铂溅射率为0.005324(每200个离子约1个)。它们从靶内200埃处出发,并且某些级联反冲能量大到铂原子能够穿过顶部表面。</p><p>此时我们先点击 TRIM 窗口顶端的 PAUSE 键暂停 TRIM 的计算,在左边“DISTRIBUTIONS”的下面,点击:Integral和DifferentialSputteredAtoms</p><p>我们观察名为 Sputtering(Integral)的图像。这个图像给出了每个到达靶表面的反冲原子能量。坐标轴单位为原子/离子(Atoms/Ion),即每个离子将会产生对应坐标数量的能到达表面的反冲原子。图中有一条标记为3.1eV的垂线,它是表面结合能E<sub>surf</sub>的平均值,在这个算例中为硅原子的。这条线的左边对应说明文字为 Not Sputtered(未溅射)的箭头。<br>在3.1eV 处,到达表面时拥有超过这个能量的原子数约为7。这是被溅射出来的原子数,并且它和我们在上面的 SPUTTERING YIELD 表中看到的数字是吻合的。</p><p>下面我们来讨论一下表面结合能。<br>这是一个原子要被溅射出来所需要的最小能量。我们应该清楚的是只有离子能量的垂直分量可以被计入。也就是说一个以入射角 45°到达表面的离子需要具有1.4倍的 E<sub>surf</sub>才能被溅射。<br>在下面你将绘制的图中,这个修正被自动加入了。显示的原子能量总是原子能量的垂直分量,而非其总能量。</p><p>表面结合能的值可能随着辐照而变化。<br>这是因为溅射使得靶变得粗糙和有损伤,而较为粗糙的靶会有较小的表面结合能。当靶变粗糙时,由于每个表面原子电子束缚减弱,溅射率会上升。因此溅射的计算不包括所有的效应。尤其是当束流使表面粗糙化时,表面结合能会随着时间的变化。<br>但是这个图像已经能够让我们估计随着时间的变化,溅射率会有怎样的变化。我们可以看到如果表面结合能被减小一半,溅射的增加倍数小于2。即使表面结合能被减少到零,溅射率只会增加两倍。因此无论靶表面发生了什么,计算结果都会精确在两倍之内。</p><p>在图像上点击SPUTTERING(Differential)将其置顶。这是之前积分图像对应的微分图像。积分图像展示了到达表面的且能量不低于为给定能量的原子个数。而这个图像展示了到达表面的原子能量的分布。典型的能量非常低,大约为1到2eV。</p><blockquote><p>停止 TRIM 计算,我们可以点击窗口的关闭键,或者点 File –> Exit来停止,弹窗点 NO(指是否要进行保存,博主觉得没必要)</p></blockquote><p>我们回到 TRIM 设置窗口,点击 TRIM DEMO 切换至 Sputtering:Xe into Nickel</p><p>这个demo将会带来一个极端的例子。</p><p>随着计算的进行,在一开的 XZ Longitudinal 图像中,你将会看到红色小点所代表的离子产生的错位开始在垂直线上集合成簇状。<br>在镍中,原子之间的空隙只略大于2埃,而这正好是月牙状红色点群中点间的距离。入射离子在靶的每个单层中只能进行一次碰撞,因而当你观察这个图像时(靶的总深度小于15个原子)你可以看到实际的原子结构。<br>在一段时间之后,绿色的点将会开始呈现出相同的条纹状。这同样是由靶中原子间距确定的。</p><p>点击 DISTRIBUTIONS 图像中的 Integral Sputtering。<br>这个图像表明每个入射离子能溅射出超过10个的原子。但是原子能量积分的斜率相比之前的硅靶要陡得多。如果表面变得粗糙化了,靶的表面结合能降低,那么溅射率可能上升为原来的两倍甚至三倍。<br>由于在这个算例中,我们无法知道表面的粗糙程度,溅射计算只能视为粗略的估计。表面的粗糙的取决于如多晶镍的晶粒大小等等因素。这些效应无法包含到 TRIM 计算中。</p><p>所有溅射原子的详细信息可以通过点击 File 按钮来保存。这会生成一个名为“SRIMOutputs\SPUTTER.txt”的文件。这个文件的一个典型例子如下(注意这个文件必须使用 MS-LineDraw 字体来生成才能得到报告中的各种线条和方框)</p><hr><p>总结:混合与溅射的计算</p><ol><li>界面混合时原子可以从初始位置移动超过100A的距离,因而可以是一个很显著的效应</li><li>会有数量相当可观的原子向表面移动。它们也能移动很远的距离。</li><li>每个入射离子若能使超过5个原子移位,溅射可以很迅速地侵蚀表面。</li><li>一些原子会从靶的深处溅射出来,正如我们看到的铂原子从表面下超过200A处溅射出来。</li></ol><hr><p>尝试了win11下虚拟机跑Linux+wine来运行SRIM<br>尝试了win11下wsl+wine来运行SRIM<br>尝试了win11下虚拟机跑win7来运行SRIM </p><p>总结一下,想折腾的可以试试Linux+wine跑SRIM,首推win11下的wsl,戳<a href="https://docs.microsoft.com/zh-cn/windows/wsl/tutorials/gui-apps">这里可以看在适用于Linux的Windows子系统上运行Linux GUI应用(预览)</a></p><p>不想折腾的可以跑个win的虚拟机,但性能会相对损失较大。<br>其次就是忍受切换语言和地区所带来的不便,使用主力机跑。<br>或者买个新的主力机(手动狗头)</p><hr><p>更新预告:创建复合靶</p>]]></content>
<summary type="html"><p>demo2 靶的混合和溅射</p></summary>
<category term="软件学习" scheme="http://paneersblog.github.io/categories/%E8%BD%AF%E4%BB%B6%E5%AD%A6%E4%B9%A0/"/>
<category term="SRIM" scheme="http://paneersblog.github.io/tags/SRIM/"/>
</entry>
<entry>
<title>Linux之shell入门</title>
<link href="http://paneersblog.github.io/60132.html"/>
<id>http://paneersblog.github.io/60132.html</id>
<published>2022-02-14T14:55:15.000Z</published>
<updated>2022-07-16T09:31:56.822Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>虽然我用的unix,但不妨碍我对Linux的热爱! </p><span id="more"></span><p>先附上<a href="https://www.linuxcool.com/">Linux命令大全(手册)</a>,可以查寻命令哦~</p><h2 id="Linux之shell速查表-基础版"><a href="#Linux之shell速查表-基础版" class="headerlink" title="Linux之shell速查表(基础版)"></a>Linux之shell速查表(基础版)</h2><table><thead><tr><th align="left">指令</th><th align="left">备注</th></tr></thead><tbody><tr><td align="left">whatis</td><td align="left">查看命令的简短描述</td></tr><tr><td align="left">ls</td><td align="left">列出当前目录下的内容</td></tr><tr><td align="left">cd</td><td align="left">改变工作目录</td></tr><tr><td align="left">pwd</td><td align="left">打印当前目录</td></tr><tr><td align="left">cp</td><td align="left">复制文件或文件夹</td></tr><tr><td align="left">less</td><td align="left">查看文件</td></tr><tr><td align="left">head/tail</td><td align="left">查看文件开头/结尾</td></tr><tr><td align="left">find</td><td align="left">查找过滤文件</td></tr><tr><td align="left">date</td><td align="left">查看系统时间</td></tr><tr><td align="left">cat</td><td align="left">合并多个文件</td></tr><tr><td align="left">cal</td><td align="left">显示当前日历</td></tr><tr><td align="left">which</td><td align="left">定位程序的储存位置</td></tr><tr><td align="left">whereis</td><td align="left">定位程序</td></tr><tr><td align="left">touch</td><td align="left">修改时间属性(文件不存在则创建文件)</td></tr><tr><td align="left">top</td><td align="left">实时显示进程动态</td></tr><tr><td align="left">rm</td><td align="left">删除文件和文件夹</td></tr><tr><td align="left">mv</td><td align="left">剪切文件和文件夹</td></tr><tr><td align="left">mkdir</td><td align="left">创建目录</td></tr></tbody></table><h2 id="Linux之shell命令-详细版"><a href="#Linux之shell命令-详细版" class="headerlink" title="Linux之shell命令(详细版)"></a>Linux之shell命令(详细版)</h2><h3 id="文件、目录操作命令"><a href="#文件、目录操作命令" class="headerlink" title="文件、目录操作命令"></a>文件、目录操作命令</h3><h4 id="写在前面:命令参数表"><a href="#写在前面:命令参数表" class="headerlink" title="写在前面:命令参数表"></a>写在前面:命令参数表</h4><table><thead><tr><th>命令参数</th><th>意义</th></tr></thead><tbody><tr><td>-f</td><td>若目标文件已存在,则会直接覆盖原文件</td></tr><tr><td>-i</td><td>若目标文件已存在,则会询问是否覆盖</td></tr><tr><td>-p</td><td>保留源文件或目录的所有属性</td></tr><tr><td>-r</td><td>递归复制文件和目录</td></tr><tr><td>-d</td><td>当复制符号连接时,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录</td></tr><tr><td>-l</td><td>对源文件建立硬连接,而非复制文件</td></tr><tr><td>-s</td><td>对源文件建立符号连接,而非复制文件</td></tr><tr><td>-b</td><td>覆盖已存在的文件目标前将目标文件备份</td></tr><tr><td>-v</td><td>详细显示cp命令执行的操作过程</td></tr><tr><td>-a</td><td>等价于“dpr”选项</td></tr></tbody></table><h4 id="ls命令"><a href="#ls命令" class="headerlink" title="ls命令"></a>ls命令</h4><p>功能:显示文件和目录的信息 </p><p><code>ls</code> 以默认方式显示当前目录文件列表 </p><p><code>ls -a</code> 显示所有文件包括隐藏文件。例如:.file 文件名称前面带小数点为隐藏文件。 </p><p><code>ls -l</code> 显示文件属性,包括大小,日期,符号连接,是否可读写及是否可执行 </p><p><code>ls -lh</code> 显示文件的大小</p><p><code>ls -lt</code> 显示文件,按照修改时间排序</p><h4 id="cd命令"><a href="#cd命令" class="headerlink" title="cd命令"></a>cd命令</h4><p>功能:改名目录</p><p><code>cd dir</code> 切换到当前目录下的dir目录</p><p><code>cd /</code> 切换到根目录</p><p><code>cd ..</code> 切换到到上一级目录</p><p><code>cd ../..</code> 切换到上二级目录</p><p><code>cd ~</code> 切换到用户目录,若是root用户,则切换到/root下</p><h4 id="cp命令"><a href="#cp命令" class="headerlink" title="cp命令"></a>cp命令</h4><p>功能:copy文件</p><p><code>cp a b</code> 将文件a复制为b</p><p><code>cp /root /a .</code> 将/root下的文件a复制到当前目录</p><p><code>cp –av a_dir b_dir</code> 将整个目录复制,两目录完全一样</p><h4 id="rm命令"><a href="#rm命令" class="headerlink" title="rm命令"></a>rm命令</h4><p>功能:删除文件或目录</p><p><code>rm file</code> 删除某一个文件</p><p><code>rm -f file</code> 删除时候不进行提示。可以于r参数配合使用</p><p><code>rm -rf dir</code> 删除当前目录下叫dir的整个目录</p><h4 id="mv命令"><a href="#mv命令" class="headerlink" title="mv命令"></a>mv命令</h4><p>功能:将文件移动走,或者改名,在uinx下面没有改名的命令,如果想改名,可以使用该命令</p><p><code>mv a b</code> 将文件a更名为b</p><h4 id="diff命令"><a href="#diff命令" class="headerlink" title="diff命令"></a>diff命令</h4><p>功能:比较文件内容</p><p><code>diff dir1 dir2</code> 比较目录1与目录2的文件列表是否相同,但不比较文件的实际内容,不同则列出</p><p><code>diff file1 file2</code> 比较文件1与文件2的内容是否相同,如果是文本格式的文件,则将不相同的内容显示,如果是二进制代码则只表示两个文件是不同的</p><p><code>comm file1 file2</code> 比较文件,显示两个文件不相同的内容</p><p><code>comm -12 file1 file2</code> 就只显示在两个文件中都存在的行</p><p><code>comm -23 file1 file2</code> 只显示在第一个文件中出现而未在第二个文件中出现的行</p><p><code>comm -13 file1 file2</code> 只显示在第一个文件中未出现而出现在第二个文件中的行</p><blockquote><p>其中参数意义:<br> -1 不显示只在第1个文件里出现过的列。(suppress lines unique to FILE1)<br> -2 不显示只在第2个文件里出现过的列。(suppress lines unique to FILE2)<br> -3 不显示在第1和第2个文件里都出现过的列。(suppress lines that appear in both files)</p></blockquote><h4 id="ln命令"><a href="#ln命令" class="headerlink" title="ln命令"></a>ln命令</h4><p>功能:建立链接。windows的快捷方式就是根据链接的原理来实现的</p><p><code>ln source_path target_path</code> 硬连接</p><p><code>ln -s source_path target_path</code> 软连接</p><p>ln是linux中又一个非常重要命令,它的功能是为某一个文件在另外一个位置建立一个同不的链接,这个命令最常用的参数是-s,具体用法是:ln –s 源文件 目标文件。 </p><p>当我们需要在不同的目录,用到相同的文件时,我们不需要在每一个需要的目录下都放一个必须相同的文件,我们只要在某个固定的目录,放上该文件,然后在其它的目录下用ln命令链接(link)它就可以,不必重复的占用磁盘空间。<br>例如:ln –s /bin/A /usr/local/bin/A</p><h3 id="查看文件内容命令"><a href="#查看文件内容命令" class="headerlink" title="查看文件内容命令"></a>查看文件内容命令</h3><h4 id="cat命令"><a href="#cat命令" class="headerlink" title="cat命令"></a>cat命令</h4><p>显示文件的内容,和DOS的type相同</p><pre><code>cat file </code></pre><h4 id="more命令"><a href="#more命令" class="headerlink" title="more命令"></a>more命令</h4><p>功能:分页显示命令</p><pre><code>more file</code></pre><p>more命令也可以通过管道符(|)与其他的命令一起使用,例如:</p><pre><code>ps ux|morels|more</code></pre><h4 id="tail-命令"><a href="#tail-命令" class="headerlink" title="tail 命令"></a>tail 命令</h4><p>功能:显示文件的最后几行</p><pre><code>tail -n 100 aaa.txt</code></pre><p> 显示文件aaa.txt文件的最后100行</p><p>4、vi命令(vim)</p><pre><code>vi file</code></pre><p>编辑文件file(按“i”键进行编辑模式,Esc退出编辑,此时可使用下文提及命令)</p><p>vi 原基本使用及命令:</p><p>输入命令的方式为先按<code>[ESC]</code>键,然后输入:</p><ol><li>:w(写入文件)</li><li>:w!(不询问方式写入文件)</li><li>:wq保存并退出</li><li>:q退出</li><li>q!不保存退出</li></ol><p>5、touch命令</p><p>ouch命令有两个功能:一是创建新的空文件,二是改变已有文件的时间戳属性。</p><p>touch命令会根据当前的系统时间更新指定文件的访问时间和修改时间。如果文件不存在,将会创建新的空文件,除非指定了”-c”或”-h”选项。</p><p>语法格式:</p><pre><code>touch [参数] [文件]</code></pre><p>附:常用参数</p><blockquote><p>-a :改变档案的读取时间记录<br>-m :改变档案的修改时间记录<br>-r :使用参考档的时间记录,与 –file 的效果一样<br>-c :不创建新文件<br>-d :设定时间与日期,可以使用各种不同的格式<br>-t :设定档案的时间记录,格式与 date 命令相同<br>–no-create :不创建新文件<br>–help :显示帮助信息<br>–version :列出版本讯息 </p></blockquote><p>注意:在修改文件的时间属性的时候,用户必须是文件的属主,或拥有写文件的访问权限。</p><h3 id="基本系统命令"><a href="#基本系统命令" class="headerlink" title="基本系统命令"></a>基本系统命令</h3><h4 id="man命令"><a href="#man命令" class="headerlink" title="man命令"></a>man命令</h4><p>功能:查看某个命令的帮助,如果你不知道某个命令的用法不懂,可以问他,他知道就回告诉你</p><p><code>man -f</code> 等同于 <code>whatis</code></p><h4 id="w命令"><a href="#w命令" class="headerlink" title="w命令"></a>w命令</h4><p>功能:显示登录用户的详细信息</p><h4 id="who命令"><a href="#who命令" class="headerlink" title="who命令"></a>who命令</h4><p>功能:显示登录用户</p><h4 id="last命令"><a href="#last命令" class="headerlink" title="last命令"></a>last命令</h4><p>功能:查看最近那些用户登录系统</p><h4 id="date命令"><a href="#date命令" class="headerlink" title="date命令"></a>date命令</h4><p>功能:系统日期设定</p><pre><code>date -s 20:30:30 设置系统时间为20:30:30date -s 2002-3-5 设置系统时期为2003-3-5date -s "060520 06:00:00" 设置系统时期为2006年5月20日6点整。</code></pre><h4 id="clock命令"><a href="#clock命令" class="headerlink" title="clock命令"></a>clock命令</h4><p>功能:时钟设置</p><pre><code>clock –r 对系统Bios中读取时间参数clock –w 将系统时间(如由date设置的时间)写入Bios</code></pre><h4 id="uname命令"><a href="#uname命令" class="headerlink" title="uname命令"></a>uname命令</h4><p>功能:查看系统版本</p><pre><code>uname -R 显示操作系统内核的version</code></pre><h4 id="关闭和重新启动系统命令"><a href="#关闭和重新启动系统命令" class="headerlink" title="关闭和重新启动系统命令"></a>关闭和重新启动系统命令</h4><pre><code>reboot 重新启动计算机shutdown -r now 重新启动计算机,停止服务后重新启动计算机shutdown -h now 关闭计算机,停止服务后再关闭系统halt 关闭计算机</code></pre><h4 id="su命令"><a href="#su命令" class="headerlink" title="su命令"></a>su命令</h4><p>功能:切换用户</p><p>su - 切换到root用户</p><p>su - paneer 切换到用户paneer</p><blockquote><p>注意:“-”很关键,使用“-”,将使用用户的环境变量</p></blockquote><h3 id="监视系统状态命令"><a href="#监视系统状态命令" class="headerlink" title="监视系统状态命令"></a>监视系统状态命令</h3><h4 id="top命令"><a href="#top命令" class="headerlink" title="top命令"></a>top命令</h4><p>功能:查看系统cpu、内存等使用情况</p><h4 id="free命令"><a href="#free命令" class="headerlink" title="free命令"></a>free命令</h4><p>功能:查看内存和swap分区使用情况</p><h4 id="uptime"><a href="#uptime" class="headerlink" title="uptime"></a>uptime</h4><p>功能:现在的时间 ,系统开机运转到现在经过的时间,连线的使用者数量,最近一分钟,五分钟和十五分钟的系统负载</p><h4 id="vmstat"><a href="#vmstat" class="headerlink" title="vmstat"></a>vmstat</h4><p>功能:监视虚拟内存使用情况</p><h4 id="ps命令"><a href="#ps命令" class="headerlink" title="ps命令"></a>ps命令</h4><p>功能:显示进程信息</p><pre><code>ps ux 显示当前用户的进程ps uxwww 显示当前用户的进程的详细信息ps aux 显示所有用户的进程ps ef 显示系统所有进程信息</code></pre><h4 id="kill命令"><a href="#kill命令" class="headerlink" title="kill命令"></a>kill命令</h4><p>功能:干掉某个进程,进程号可以通过ps命令得到</p><pre><code>kill -9 1001 将进程编号为1001的程序干掉kill all -9 apache 将所有名字为apapche的程序杀死</code></pre><hr><p>eeeeeee<br>好困啊不想写了,估计也没人看到这。。。</p><hr><p>想认真学的小伙伴,<br>推荐看一下大厂鱼皮的<a href="https://www.bilibili.com/video/BV1ev411G7VE/?spm_id_from=333.788.recommend_more_video.0">最快Linux入门教程+最新学习路线!程序员必备组合拳</a><br>真的很赞哦~~~</p><hr><p>随缘填坑吧</p><p>参考blog:<br><a href="https://blog.csdn.net/LH0912666/article/details/87897629">https://blog.csdn.net/LH0912666/article/details/87897629</a></p>]]></content>
<summary type="html"><p>虽然我用的unix,但不妨碍我对Linux的热爱! </p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Linux" scheme="http://paneersblog.github.io/tags/Linux/"/>
</entry>
<entry>
<title>DOS常用命令</title>
<link href="http://paneersblog.github.io/56201.html"/>
<id>http://paneersblog.github.io/56201.html</id>
<published>2022-02-13T13:44:00.000Z</published>
<updated>2022-07-16T09:32:04.655Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>DOS常用命令(cmd.exe)</p><span id="more"></span><h2 id="基础命令"><a href="#基础命令" class="headerlink" title="基础命令"></a>基础命令</h2><table><thead><tr><th align="left">命令</th><th align="left">备注</th></tr></thead><tbody><tr><td align="left">cd\</td><td align="left">返回到根目录</td></tr><tr><td align="left">cd..</td><td align="left">返回上一级目录</td></tr><tr><td align="left">cd d:</td><td align="left">切换盘符</td></tr><tr><td align="left">cd a</td><td align="left">进入a目录</td></tr><tr><td align="left">md</td><td align="left">建立目录(即新建文件夹)</td></tr><tr><td align="left">rd</td><td align="left">删除目录</td></tr><tr><td align="left">dir</td><td align="left">显示目录</td></tr><tr><td align="left">dir /b</td><td align="left">显示目录只显示文件名</td></tr><tr><td align="left">dir /p</td><td align="left">分页显示目录</td></tr><tr><td align="left">copy</td><td align="left">复制文件</td></tr><tr><td align="left">ren</td><td align="left">更改文件名</td></tr><tr><td align="left">cls</td><td align="left">清除屏幕</td></tr><tr><td align="left">del</td><td align="left">删除文件</td></tr><tr><td align="left">time</td><td align="left">显示时间</td></tr><tr><td align="left">date</td><td align="left">显示日期</td></tr></tbody></table><h2 id="命令管道符-“-”"><a href="#命令管道符-“-”" class="headerlink" title="命令管道符 “|”"></a>命令管道符 “|”</h2><p>格式:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">命令<span class="number">1</span> | 命令<span class="number">2</span> | 命令<span class="number">3</span> |... </span><br></pre></td></tr></table></figure><p>管道命令能够将一个命令的执行结果进行筛选,只保留我们需要的信息。如:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">dir</span> c:/ | <span class="built_in">find</span> "txt"</span><br></pre></td></tr></table></figure><h2 id="查看文件夹目录结构"><a href="#查看文件夹目录结构" class="headerlink" title="查看文件夹目录结构"></a>查看文件夹目录结构</h2><p>顾名思义,通过“tree”来实现,如以下所示,其中“/f”可以显示文件目录结构的同时显示文件。“>”的意义详见下文。</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">tree</span> > list.txt</span><br><span class="line"><span class="built_in">tree</span> /f > list.txt</span><br></pre></td></tr></table></figure><h2 id="“-lt-”、”-gt-”、”-lt-lt-”、”-gt-gt-”等"><a href="#“-lt-”、”-gt-”、”-lt-lt-”、”-gt-gt-”等" class="headerlink" title="“<”、”>”、”<<”、”>>”等"></a>“<”、”>”、”<<”、”>>”等</h2><table><thead><tr><th align="left">命令</th><th align="left">备注</th></tr></thead><tbody><tr><td align="left">></td><td align="left">输出重定向</td></tr><tr><td align="left"><</td><td align="left">输入重定向</td></tr><tr><td align="left"><<</td><td align="left">输入追加</td></tr><tr><td align="left">>></td><td align="left">输出追加</td></tr></tbody></table><p>用法如下:</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">sort</span> <<span class="number">1</span>.txt</span><br></pre></td></tr></table></figure><p>其作用是将“sort”得到的结果输出在“1.txt”文件中 </p><p>备注: </p><ul><li>>: 将命令输出写入到文件或设备(例如打印机)中,而不是写在命令提示符窗口中。</li><li><:从文件中而不是从键盘中读入命令输入。</li><li>>>: 将命令输出添加到文件末尾而不删除文件中的信息。</li><li>>&: 将一个句柄的输出写入到另一个句柄的输入中。</li><li><&: 从一个句柄读取输入并将其写入到另一个句柄输出中。</li><li>|: 从一个命令中读取输出并将其写入另一个命令的输入中。也称作管道。</li></ul><hr><p><em><strong>不定期更新,欢迎评论区补充~</strong></em></p><hr><p>参考视频<a href="https://www.bilibili.com/video/BV19v411g7h7?from=search&seid=5443457631883777453&spm_id_from=333.337.0.0">地址</a></p>]]></content>
<summary type="html"><p>DOS常用命令(cmd.exe)</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="DOS" scheme="http://paneersblog.github.io/tags/DOS/"/>
</entry>
<entry>
<title>Python入门笔记(五)</title>
<link href="http://paneersblog.github.io/52970.html"/>
<id>http://paneersblog.github.io/52970.html</id>
<published>2022-02-11T16:08:19.000Z</published>
<updated>2022-07-16T09:28:48.147Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><hr><h3 id="位运算符-了解"><a href="#位运算符-了解" class="headerlink" title="位运算符(了解)"></a>位运算符(了解)</h3><p>位运算是把数字看作二进制数来进行计算的,所以需要先将要执行运算的数据转换为二进制,然后才能进行执行运算</p><ul><li>“位与”运算(&)<ul><li>两个操作数据的二进制表示,只有对应数位都是1时,结果数位才是1,否则为0</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(<span class="number">12</span>&<span class="number">8</span>) <span class="comment"># 输出结果为“8”</span></span><br></pre></td></tr></table></figure><ul><li>“位或”运算(|)<ul><li>两个操作数的二进制表示,只有对应数位都是0时,结果数位才是0,否则为1</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(<span class="number">8</span>|<span class="number">4</span>) <span class="comment"># 输出结果为“12”</span></span><br></pre></td></tr></table></figure><ul><li>“位异或”运算(^)<ul><li>两个操作数据的二进制相同(同时为0或同时为1),结果为零,否则为1</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(<span class="number">31</span>^<span class="number">22</span>) <span class="comment"># 结果为“9”</span></span><br></pre></td></tr></table></figure><ul><li>“位取反”运算(~)<ul><li>操作数据中对应的二进制数1修改为0,0修改为1</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(~<span class="number">123</span>) <span class="comment"># 结果为“-124”</span></span><br></pre></td></tr></table></figure><ul><li>“左移位”运算(<<)<ul><li>将一个二进制数向左移动指定的位数,左边(高位端)溢出的位被丢弃,右边(低位端)的空位用0补充</li><li>左移位运算相当于乘以2的N次幂</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(<span class="number">2</span><<<span class="number">2</span>) <span class="comment"># 将2向左移动2位 得8</span></span><br><span class="line"><span class="built_in">print</span>(<span class="number">2</span><<<span class="number">3</span>) <span class="comment"># 将2向左移动3位 得16</span></span><br></pre></td></tr></table></figure><ul><li>“右移位”运算(>>)<ul><li>将一个二进制数向右移动指定的位数,右边(低位端)溢出的位被丢弃左边(高位端)的空位端,如果最高位是O(正数)左侧空位填0,如果最高位是1(负数),左侧空位填1</li><li>右移位运算相当于除以2的N次幂</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">print</span>(<span class="number">8</span>>><span class="number">2</span>) <span class="comment"># 将8右移2位 得2</span></span><br><span class="line"><span class="built_in">print</span>(-<span class="number">8</span>>><span class="number">2</span>) <span class="comment"># 将-8右移2位 得-2</span></span><br></pre></td></tr></table></figure><h2 id="运算符的优先级"><a href="#运算符的优先级" class="headerlink" title="运算符的优先级"></a>运算符的优先级</h2><table><thead><tr><th align="left">运算符</th><th align="left">说明</th></tr></thead><tbody><tr><td align="left">**</td><td align="left">幂</td></tr><tr><td align="left">~、+、-</td><td align="left">取反、正号和负号</td></tr><tr><td align="left">*、/、%、//</td><td align="left">算术运算符</td></tr><tr><td align="left">| +、-</td><td align="left">算术运算符</td></tr><tr><td align="left"><<、>></td><td align="left">为运算符中左移和右移</td></tr><tr><td align="left">&</td><td align="left">位运算符中的位与</td></tr><tr><td align="left">^</td><td align="left">位运算符中的异或</td></tr><tr><td align="left">|</td><td align="left">位运算符中的位或</td></tr><tr><td align="left"><、<=、>、>=、!=、==</td><td align="left">比较运算符</td></tr></tbody></table><h2 id="程序的描述方式"><a href="#程序的描述方式" class="headerlink" title="程序的描述方式"></a>程序的描述方式</h2><p>自然语言:<br>使用人类语言,直接描述程序,比如:IPO描述</p><p>流程图:<br>是最直观易懂的表达方式,主要适用于较短的算法</p><p>伪代码:<br>介于自然语言和编程语言之间的一种算法描述语言</p><h2 id="程序的组织结构"><a href="#程序的组织结构" class="headerlink" title="程序的组织结构"></a>程序的组织结构</h2><p>顺序结构:<br>按照程序语句的自然顺序,从上到下,依次执行每条语句的程序 </p><p>选择结构:<br>按照条件选择执行不同的代码段</p><p>循环结构:<br>在一定的条件下反复执行某段程序的流程结构</p><h2 id="顺序结构"><a href="#顺序结构" class="headerlink" title="顺序结构"></a>顺序结构</h2><p>顺序结构是程序中最基础的语句,赋值语句、输入/输出语句、模块导入语句等都是顺序结构的语句</p><table><thead><tr><th align="left">赋值类别</th><th align="left">细化分类</th><th align="left">示例</th><th align="left">注意</th></tr></thead><tbody><tr><td align="left">增强赋值运算</td><td align="left">增强赋值运算</td><td align="left">i+=1</td><td align="left">相当于i=i+1</td></tr><tr><td align="left">序列分解赋值</td><td align="left">元组分解赋值</td><td align="left">name,age=’Paneer’,20</td><td align="left"></td></tr><tr><td align="left"></td><td align="left">列表分解赋值</td><td align="left">[name,age]=[‘Paneer’,20]</td><td align="left"></td></tr><tr><td align="left"></td><td align="left">字符串分解赋值</td><td align="left">a,b,c,d=’room’</td><td align="left">r、o、o、m四个字符分别赋值给a、b、c、d</td></tr><tr><td align="left">扩展序列解包</td><td align="left">*号匹配赋值</td><td align="left">a,*b=’room’</td><td align="left">r赋值a,剩下的o、o、m赋值给b</td></tr></tbody></table><h2 id="常用的条件语句"><a href="#常用的条件语句" class="headerlink" title="常用的条件语句"></a>常用的条件语句</h2><h3 id="if语句"><a href="#if语句" class="headerlink" title="if语句"></a>if语句</h3><p>语法结构:</p><pre><code>if 表达式: 语句块</code></pre><p>汉语关联词:<br>如果…就…</p><p>执行顺序:<br>如果表达式的值为<code>True</code>,就执行语句块<br>如果表达式的值为<code>False</code>,就跳过语句块,继续执行后面的语句</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">num = <span class="number">98</span></span><br><span class="line"><span class="keyword">if</span> n%<span class="number">2</span>:</span><br><span class="line"> <span class="built_in">print</span>(n,<span class="string">'为偶数'</span>)</span><br><span class="line"><span class="keyword">if</span> <span class="keyword">not</span> n%<span class="number">2</span>:</span><br><span class="line"> <span class="built_in">print</span>(n,<span class="string">'为奇数'</span>)</span><br></pre></td></tr></table></figure><blockquote><p>if语句若语句块只有一句代码,可以将语句块直接写在冒号后面</p></blockquote><h3 id="if…else…语句"><a href="#if…else…语句" class="headerlink" title="if…else…语句"></a>if…else…语句</h3><p>语法结构为:</p><pre><code>if 表达式: 语句块1else: 语句块2</code></pre><p>汉语关联词:<br>如果…否则…</p><p>执行顺序:<br>如果表达式值为<code>True</code>,执行语句1,否则执行语句2</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">number=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入您的六位彩票号码'</span>))</span><br><span class="line"><span class="keyword">if</span> number=<span class="number">876543</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'恭喜!中奖了'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'很遗憾,没有中奖'</span>)</span><br><span class="line"><span class="comment"># 以上代码可用条件表达式简化:</span></span><br><span class="line">number=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入您的六位彩票号码'</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'恭喜!中奖了'</span> <span class="keyword">if</span> number==<span class="number">876543</span> <span class="keyword">else</span> <span class="string">'很遗憾,没有中奖'</span>)</span><br></pre></td></tr></table></figure><h3 id="if…elif…else语句"><a href="#if…elif…else语句" class="headerlink" title="if…elif…else语句"></a>if…elif…else语句</h3><p>语法结构: </p><pre><code>if 表达式1: 语句块1elif 表达式2: 语句块2 ...elif 表达式n: 语句块nelse: 语句块n+1</code></pre><p>示例为:</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">score=<span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入您的成绩:'</span>))</span><br><span class="line"><span class="keyword">if</span> score<<span class="number">0</span> <span class="keyword">or</span> score><span class="number">100</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'ERROR'</span>)</span><br><span class="line"><span class="keyword">elif</span> <span class="number">0</span><=score<<span class="number">60</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'E'</span>)</span><br><span class="line"><span class="keyword">elif</span> <span class="number">60</span><score<=<span class="number">70</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'D'</span>)</span><br><span class="line"><span class="keyword">elif</span> <span class="number">70</span><score<=<span class="number">80</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'C'</span>)</span><br><span class="line"><span class="keyword">elif</span> <span class="number">80</span><score<=<span class="number">90</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'B'</span>)</span><br><span class="line"><span class="keyword">else</span>:</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">"A"</span>)</span><br></pre></td></tr></table></figure><h3 id="if语句的嵌套"><a href="#if语句的嵌套" class="headerlink" title="if语句的嵌套"></a>if语句的嵌套</h3><ul><li><p>形式1</p><pre><code>if 表达式1: if 表达式2: 语句块1 else: 语句块2</code></pre></li><li><p>形式2</p><pre><code>if 表达式1: if 表达式2: 语句块1 else: 语句块2else: if 表达式3: 语句块3 else: 语句块4</code></pre></li></ul>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Python入门笔记(四)</title>
<link href="http://paneersblog.github.io/3156.html"/>
<id>http://paneersblog.github.io/3156.html</id>
<published>2022-02-10T16:39:06.000Z</published>
<updated>2022-07-16T09:28:48.131Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><hr><h2 id="数据类型之间的转换"><a href="#数据类型之间的转换" class="headerlink" title="数据类型之间的转换"></a>数据类型之间的转换</h2><h3 id="隐式类型转换"><a href="#隐式类型转换" class="headerlink" title="隐式类型转换"></a>隐式类型转换</h3><p>通过数学运算可以隐式将 int类型 转换成 float类型。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 12.数据类型隐式转换</span></span><br><span class="line">x = <span class="number">10</span></span><br><span class="line">y = <span class="number">3</span></span><br><span class="line">z = x/y</span><br><span class="line"><span class="built_in">print</span>(z,<span class="built_in">type</span>(z),<span class="built_in">type</span>(x)) <span class="comment"># 则此时的"z"即为 float类型</span></span><br></pre></td></tr></table></figure><h3 id="显式类型转换"><a href="#显式类型转换" class="headerlink" title="显式类型转换"></a>显式类型转换</h3><table><thead><tr><th align="left">函数</th><th align="left">说明</th></tr></thead><tbody><tr><td align="left">int(x)</td><td align="left">将x转换为整数类型</td></tr><tr><td align="left">float(x)</td><td align="left">将x转换为浮点数类型</td></tr><tr><td align="left">str(x)</td><td align="left">将x转换为字符串</td></tr><tr><td align="left">chr(x)</td><td align="left">将整数x转换为一个字符</td></tr><tr><td align="left">ord(x)</td><td align="left">将一个字符x转换为其对应的整数值</td></tr><tr><td align="left">hex(x)</td><td align="left">将一个整数x转换为一个十六进制字符串</td></tr><tr><td align="left">oct(x)</td><td align="left">将一个整数x转换为一个八进制字符串</td></tr><tr><td align="left">bin(x)</td><td align="left">将一个整数x转换为一个二进制字符串</td></tr></tbody></table><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 13.数据类型显式转换</span></span><br><span class="line"><span class="comment"># float TO int 只保留整数部分</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">int</span>(<span class="number">3.14</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">int</span>(<span class="number">3.9</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">int</span>(-<span class="number">3.14</span>))</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">int</span>(-<span class="number">3.9</span>))</span><br><span class="line"><span class="comment"># int TO float 在整数后加" .0"</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">float</span>(<span class="number">10</span>))</span><br><span class="line"><span class="comment"># str TO int</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">int</span>(<span class="string">'100'</span>)+<span class="built_in">int</span>(<span class="string">'200'</span>)) <span class="comment"># 注意,此时100与200均加了单引号,为字符串类型</span></span><br><span class="line"><span class="comment"># str TO float</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">float</span>(<span class="string">'3.14'</span>))</span><br><span class="line"><span class="comment"># 注意,若字符串类型如"10a"这样,当其转换为int或float类型时会产生"ValueError"</span></span><br><span class="line"><span class="comment"># 注意,类似int('3.14')这样的语句,因为字符串"3.14"不是整数,也会产生"ValueError"</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># chr & ord</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">ord</span>(<span class="string">'圆'</span>)) <span class="comment"># 22278 将"圆"转换成对应的数值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">chr</span>(<span class="number">22278</span>)) <span class="comment"># 将数值转换成对应的字符</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 进制之间的转换 十进制 TO Other</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">hex</span>(<span class="number">22278</span>)) <span class="comment"># 0x5706</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">oct</span>(<span class="number">22278</span>)) <span class="comment"># 0o53406</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">bin</span>(<span class="number">22278</span>)) <span class="comment"># 0b101011100000110</span></span><br></pre></td></tr></table></figure><h2 id="eval-函数"><a href="#eval-函数" class="headerlink" title="eval()函数"></a><code>eval()</code>函数</h2><p><code>eval(s)</code>函数将去掉字符串s最外侧的引号,并按照Python语句方式执行去掉引号后的字符串<br>其语法格式为:</p><pre><code>变量=eval(字符串)</code></pre><p><code>eval()</code>函数经常和<code>input()</code>函数一起使用,来获取用户输入的数值型 </p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># eval()函数</span></span><br><span class="line">s = <span class="string">'3.14+2'</span></span><br><span class="line"><span class="built_in">print</span>(s,<span class="built_in">type</span>(s)) <span class="comment"># 3.14+2 <class 'str'></span></span><br><span class="line">x = <span class="built_in">eval</span>(s)</span><br><span class="line"><span class="built_in">print</span>(x,<span class="built_in">type</span>(x)) <span class="comment"># 5.140000000000001 <class 'float'></span></span><br><span class="line"></span><br><span class="line">age = <span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入您的年龄:'</span>))</span><br><span class="line"><span class="built_in">print</span>(age,<span class="built_in">type</span>(age)) <span class="comment"># 键入"21",得"21 <class 'int'>" 相当于int(age)</span></span><br><span class="line">height = <span class="built_in">eval</span>(<span class="built_in">input</span>(<span class="string">'请输入您的身高:'</span>))</span><br><span class="line"><span class="built_in">print</span>(height,<span class="built_in">type</span>(height)) <span class="comment"># 键入"180.1",得"180.1 <class 'float'>" 相当于float(height)</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># eval()报错情况</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">eval</span>(<span class="string">'hello'</span>)) <span class="comment"># NameError: name 'hello' is not defined.</span></span><br></pre></td></tr></table></figure><h2 id="不同的进制数"><a href="#不同的进制数" class="headerlink" title="不同的进制数"></a>不同的进制数</h2><p>进制数的进位</p><ul><li>二进制:0或1组成,满二进一,以Ob开头或0B开头</li><li>八进制:0~7组成,满八进一,以Oo或0O开头</li><li>十进制:0~9组成,满十进一</li><li>十六进制:0~9和a~f或A~F组成,满十六进一,以0x或0X开头</li></ul><h2 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h2><h3 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h3><p>算术运算符是处理四则运算的符号,在数字的处理中应用的最多</p><table><thead><tr><th align="left">运算符</th><th align="left">说明</th><th align="left">示例</th><th align="left">结果</th></tr></thead><tbody><tr><td align="left">+</td><td align="left">加</td><td align="left">1+1</td><td align="left">2</td></tr><tr><td align="left">-</td><td align="left">减</td><td align="left">1-1</td><td align="left">0</td></tr><tr><td align="left">*</td><td align="left">乘</td><td align="left">2*3</td><td align="left">6</td></tr><tr><td align="left">/</td><td align="left">除</td><td align="left">10/2</td><td align="left">5</td></tr><tr><td align="left">//</td><td align="left">整除</td><td align="left">10//3</td><td align="left">3</td></tr><tr><td align="left">%</td><td align="left">取余</td><td align="left">10%3</td><td align="left">1</td></tr><tr><td align="left">**</td><td align="left">幂运算</td><td align="left">2**4</td><td align="left">16</td></tr></tbody></table><p>算术运算符的优先级:</p><ul><li>先乘除后加减</li><li>同级运算从左到右依次运算</li><li>可以使用()调整计算优先级<ul><li>第一级:**</li><li>第二级:*,/,%,//</li><li>第三级:+,-</li></ul></li></ul><h3 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h3><p>主要用于为变量进行赋值<br>直接把赋值运算符“=”右边的值赋给左边的变量</p><table><thead><tr><th align="left">运算符</th><th align="left">说明</th><th align="left">示例</th><th align="left">展开形式</th></tr></thead><tbody><tr><td align="left">=</td><td align="left">简单的赋值运算</td><td align="left">x=y</td><td align="left">x=y</td></tr><tr><td align="left">+=</td><td align="left">加赋值</td><td align="left">x+=y</td><td align="left">x=x+y</td></tr><tr><td align="left">-=</td><td align="left">减赋值</td><td align="left">x-=y</td><td align="left">x=x-y</td></tr><tr><td align="left">*=</td><td align="left">乘赋值</td><td align="left">x*=y</td><td align="left">x=x*y</td></tr><tr><td align="left">/=</td><td align="left">除赋值</td><td align="left">x/=y</td><td align="left">x=x/y</td></tr><tr><td align="left">%=</td><td align="left">取余赋值</td><td align="left">x%=y</td><td align="left">x=x%y</td></tr><tr><td align="left">**=</td><td align="left">幂赋值</td><td align="left">x**=y</td><td align="left">x=x**y</td></tr><tr><td align="left">//=</td><td align="left">整除赋值</td><td align="left">x/=y</td><td align="left">x=x/y</td></tr></tbody></table><p>另外,</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># python支持链式赋值</span></span><br><span class="line">a=b=c=<span class="number">100</span> <span class="comment"># 相当于执行了 a=100 b=100 c=100</span></span><br><span class="line"><span class="comment"># python支持系列解包赋值</span></span><br><span class="line">a,b=<span class="number">10</span>,<span class="number">20</span> <span class="comment"># 相当于执行了 a=10 b=20</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># python中交换两个变量的值</span></span><br><span class="line">b,a=a,b</span><br></pre></td></tr></table></figure><h3 id="比较运算符"><a href="#比较运算符" class="headerlink" title="比较运算符"></a>比较运算符</h3><p>也称关系运算符,用于对变量或表达式的结果进行大小、真假等比较,如果比较结果为真,则值为True,比较结果为假,值为False</p><table><thead><tr><th align="left">运算符</th><th align="left">作用</th><th align="left">举例</th><th align="left">结果</th></tr></thead><tbody><tr><td align="left">></td><td align="left">大于</td><td align="left">98>90</td><td align="left">True</td></tr><tr><td align="left"><</td><td align="left">小于</td><td align="left">98<90</td><td align="left">False</td></tr><tr><td align="left">==</td><td align="left">等于</td><td align="left">98==90</td><td align="left">False</td></tr><tr><td align="left">!=</td><td align="left">不等于</td><td align="left">98!=90</td><td align="left">True</td></tr><tr><td align="left">>=</td><td align="left">大于等于</td><td align="left">98>=98</td><td align="left">True</td></tr><tr><td align="left"><=</td><td align="left">小于等于</td><td align="left">98<=98</td><td align="left">True</td></tr></tbody></table><h3 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h3><p>逻辑运算符是对真和假两种布尔值进行运算,运算的结果仍是个布尔值</p><table><thead><tr><th align="left">运算符</th><th align="left">含义</th><th align="left">用法</th><th align="left">结合方向</th></tr></thead><tbody><tr><td align="left">and</td><td align="left">逻辑与</td><td align="left">表达式1 and 表达式2</td><td align="left">从左到右</td></tr><tr><td align="left">or</td><td align="left">逻辑或</td><td align="left">表达式1 or 表达式2</td><td align="left">从左到右</td></tr><tr><td align="left">not</td><td align="left">逻辑非</td><td align="left">not 表达式</td><td align="left">从右到左</td></tr></tbody></table><p>使用逻辑运算符进行逻辑运算的结果如下</p><table><thead><tr><th align="left">表达式1</th><th align="left">表达式2</th><th align="left">1 and 2</th><th align="left">1 or 2</th><th align="left">not 1</th></tr></thead><tbody><tr><td align="left">T</td><td align="left">T</td><td align="left">T</td><td align="left">T</td><td align="left">F</td></tr><tr><td align="left">T</td><td align="left">F</td><td align="left">F</td><td align="left">T</td><td align="left">F</td></tr><tr><td align="left">F</td><td align="left">T</td><td align="left">F</td><td align="left">T</td><td align="left">T</td></tr><tr><td align="left">F</td><td align="left">F</td><td align="left">F</td><td align="left">F</td><td align="left">T</td></tr></tbody></table><blockquote><p>注:上表T代表True,F代表False </p><ul><li>A and B中,若A为False,则不对B进行计算,直接输出False</li><li>A or B中,若A为true,则不对B进行计算,直接输出True<br>not 中,<code>print(not(8>7))</code>输出结果为False</li></ul></blockquote>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>Python入门笔记(三)</title>
<link href="http://paneersblog.github.io/25237.html"/>
<id>http://paneersblog.github.io/25237.html</id>
<published>2022-02-09T15:26:33.000Z</published>
<updated>2022-07-16T09:28:48.132Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><hr><h3 id="字符串类型"><a href="#字符串类型" class="headerlink" title="字符串类型"></a>字符串类型</h3><h4 id="转义字符"><a href="#转义字符" class="headerlink" title="转义字符"></a>转义字符</h4><p>反斜杠字符(\)是一个特殊字符,在Python字符串中表示“转义”,该字符与后面相邻的一个字符共同组成一个新的含义。<br>在字符串界定符前加上r或R,转义字符失效,将原样输出。</p><table><thead><tr><th align="center">转义字符</th><th align="center">说明</th></tr></thead><tbody><tr><td align="center"><code>\n</code></td><td align="center">换行符</td></tr><tr><td align="center"><code>\t</code></td><td align="center">水平制表符,横向跳转到下一个制表位</td></tr><tr><td align="center"><code>\"</code></td><td align="center">双引号</td></tr><tr><td align="center"><code>\'</code></td><td align="center">单引号</td></tr><tr><td align="center"><code>\\</code></td><td align="center">一个反斜杠</td></tr></tbody></table><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 8.转义字符</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'Paneer'</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'真帅'</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'-----------'</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'Paneer\n真帅'</span>) <span class="comment"># 遇到\n即换行,可连续进行换行。</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">r'Paneer\n真帅'</span>) <span class="comment"># 在界定符''前加r(R),则原样输出</span></span><br></pre></td></tr></table></figure><h4 id="字符串的索引"><a href="#字符串的索引" class="headerlink" title="字符串的索引"></a>字符串的索引</h4><p>对字符串中某个字符的检索称作索引<br>语法结构为:</p><pre><code>字符串或字符串变量[序号]</code></pre><blockquote><p>注,正向递增序号从“0”开始,反向递减序号从“-1”开始</p></blockquote><h4 id="字符串的切片"><a href="#字符串的切片" class="headerlink" title="字符串的切片"></a>字符串的切片</h4><p>对字符串中某个子串或区间的检索称为切片<br>语法结构为:</p><pre><code>字符串或字符串变量[N:M]</code></pre><p>切片获取字符串中从N(包含)到M(不包含)的子字符串。</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 9.字符串的索引和切片</span></span><br><span class="line">s = <span class="string">'helloworld'</span></span><br><span class="line"><span class="built_in">print</span>(s[<span class="number">1</span>],s[-<span class="number">9</span>]) <span class="comment"># 输出"e e",对于字符串"s"来讲正向第"1"个(从0开始)和逆向第"9"个都是"e"</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'helloworld'</span>[<span class="number">9</span>])</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'helloworld'</span>[-<span class="number">1</span>])</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(s[<span class="number">2</span>:<span class="number">7</span>]) <span class="comment"># 正向递增序列切片</span></span><br><span class="line"><span class="built_in">print</span>(s[-<span class="number">8</span>:-<span class="number">3</span>]) <span class="comment"># 逆向递减序列切片</span></span><br><span class="line"><span class="comment"># N 默认是0</span></span><br><span class="line"><span class="built_in">print</span>(s[:<span class="number">5</span>])</span><br><span class="line"><span class="comment"># M 默认是到字符串结尾</span></span><br><span class="line"><span class="built_in">print</span>(s[<span class="number">5</span>:])</span><br></pre></td></tr></table></figure><h4 id="字符串类型的操作"><a href="#字符串类型的操作" class="headerlink" title="字符串类型的操作"></a>字符串类型的操作</h4><table><thead><tr><th align="left">操作符</th><th align="left">描述</th></tr></thead><tbody><tr><td align="left">x+y</td><td align="left">连接两个字符x与y</td></tr><tr><td align="left">x*n或n*x</td><td align="left">复制n次字符串</td></tr><tr><td align="left">x in s</td><td align="left">若x是s的子串,则结果为true,否则为false</td></tr></tbody></table><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 10.字符串类型的操作</span></span><br><span class="line">x = <span class="string">'2022年'</span></span><br><span class="line">y = <span class="string">'北京冬奥会'</span></span><br><span class="line"><span class="built_in">print</span>(x+y)</span><br><span class="line"><span class="built_in">print</span>(<span class="number">10</span>*x,x*<span class="number">10</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'北京'</span> <span class="keyword">in</span> y)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'上海'</span> <span class="keyword">in</span> y)</span><br></pre></td></tr></table></figure><h3 id="布尔类型"><a href="#布尔类型" class="headerlink" title="布尔类型"></a>布尔类型</h3><ul><li>用来表示真值或假值</li><li>在Python中使用标识符<code>True</code>和<code>False</code>表示布尔类型的值</li><li>布尔类型可转换化为数值,<code>True</code>表示1 <code>False</code>表示O</li><li>所有对象都有一个布尔值,使用内置函数<code>bool()</code>进行测试</li><li>布尔值为假的情况<ul><li><code>False</code>或者是<code>None</code></li><li>数值中的0,包含0,0.0,虚数0</li><li>空序列,包含空字符串、空元组、空列表、空字典</li><li>自定义对象的实例,该对象的<code>__bool()__</code>方法返回<code>False</code>或<code>__len___()</code>方法返回0</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 11.布尔类型</span></span><br><span class="line">x = <span class="literal">True</span></span><br><span class="line"><span class="built_in">print</span>(x) <span class="comment"># 输出"True"</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(x)) <span class="comment"># 输出"<class 'bool'>"</span></span><br><span class="line"><span class="built_in">print</span>(<span class="literal">True</span>+<span class="number">10</span>) <span class="comment"># 1+10</span></span><br><span class="line"><span class="built_in">print</span>(<span class="literal">False</span>+<span class="number">10</span>) <span class="comment"># 0+10</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 测试对象的布尔值</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">bool</span>(<span class="number">18</span>)) <span class="comment"># True</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">bool</span>(<span class="number">0</span>),<span class="built_in">bool</span>(<span class="number">0.0</span>)) <span class="comment"># False</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">bool</span>(<span class="string">'北京欢迎你'</span>)) <span class="comment"># True</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">bool</span>(<span class="string">''</span>)) <span class="comment"># 空字符串,False</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">bool</span>(<span class="literal">False</span>)) <span class="comment"># False</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">bool</span>(<span class="literal">None</span>)) <span class="comment"># False</span></span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
<entry>
<title>test page (music)</title>
<link href="http://paneersblog.github.io/1.html"/>
<id>http://paneersblog.github.io/1.html</id>
<published>2022-02-09T09:57:12.000Z</published>
<updated>2022-07-19T04:43:13.511Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>音乐播放器测试(进来听歌)</p><span id="more"></span> <div id="aplayer-onsDuiFC" class="aplayer aplayer-tag-marker meting-tag-marker" data-id="445546453" data-server="netease" data-type="song" data-mode="circulation" data-autoplay="false" data-mutex="true" data-listmaxheight="340px" data-preload="auto" data-theme="#49A6F9" data-volume="0.5" ></div><blockquote><p>Embed aplayer in Hexo posts/pages. <a href="https://github.com/MoePlayer/hexo-tag-aplayer">GitHub 项目地址</a>,感谢作者。</p></blockquote><p>插件功能很强大,这里主要介绍如何使用其中一个功能<code>MeingJS</code>,想了解更多功能可以去看<a href="https://github.com/MoePlayer/hexo-tag-aplayer/blob/master/docs/README-zh_cn.md">官方文档</a>。</p><p><code>MeingJS</code>支持从网易云音乐等平台获取 id(歌曲 id / 播放列表 id / 相册 id / 搜索关键字)后配合代码模板,即可在页面显示。</p><h2 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h2><pre><code>npm install --save hexo-tag-aplayer</code></pre><blockquote><p>若无法正常显示播放器,则可能是下列 js 版本过低</p><ul><li>APlayer.js > 1.8.0</li><li>Meting.js > 1.1.1</li></ul></blockquote><h2 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h2><ol><li>配置hexo配置文件<code>_config.yml</code>,添加如下(在文件最后直接粘贴即可):</li></ol><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">aplayer: </span><br><span class="line"> meting: true</span><br><span class="line"># 注意,冒号后要加一个空格</span><br></pre></td></tr></table></figure><ol start="2"><li>获取歌词、歌单ID。</li></ol><blockquote><p>没什么多说的,教程很多。<br>注,此测试页用的id为 445546453</p></blockquote><ol start="3"><li><p>在markdown文件中添加如下代码模版即可:</p><pre><code> {% meting "获取的id" "netease" "song" "mini:ture" "volume:0.5" "theme:#49A6F9" %}</code></pre></li></ol><p>注意,该代码模版可能不会在markdown渲染器中渲染出来(类似插入图片,详细参考<a href="%E6%88%91%E7%9A%84Markdown%E7%AC%94%E8%AE%B0.md">Markdown速查表</a>)<br>4. hexo clean & hexo g & hexo d 三连即可看到!</p><h2 id="标签参数"><a href="#标签参数" class="headerlink" title="标签参数"></a>标签参数</h2><blockquote><p>下表中的<code>音乐平台</code>分别代表:<code>网易云</code>、<code>QQ音乐</code>、<code>酷狗</code>、<code>百度</code><br>可按照此表在代码模板中修改</p></blockquote><table><thead><tr><th align="left">选项</th><th align="left">默认值</th><th>描述</th></tr></thead><tbody><tr><td align="left">id</td><td align="left">必须值</td><td>歌曲 id / 播放列表 id / 相册 id / 搜索关键字</td></tr><tr><td align="left">server</td><td align="left">必须值</td><td>音乐平台: netease, tencent,kugou,baidu</td></tr><tr><td align="left">type</td><td align="left">必须值</td><td>song, playlist, album, search, artist</td></tr><tr><td align="left">fixed</td><td align="left">false</td><td>开启固定模式</td></tr><tr><td align="left">mini</td><td align="left">false</td><td>开启迷你模式</td></tr><tr><td align="left">loop</td><td align="left">all</td><td>列表循环模式:all, one,none</td></tr><tr><td align="left">order</td><td align="left">list</td><td>列表播放模式: list, random</td></tr><tr><td align="left">volume</td><td align="left">0.7</td><td>播放器音量</td></tr><tr><td align="left">lrctype</td><td align="left">0</td><td>歌词格式类型</td></tr></tbody></table><p>参考链接:<a href="https://plushine.cn/54808.html#%E9%9F%B3%E4%B9%90%E6%92%AD%E6%94%BE%E5%99%A8">XJHui’sBlog</a></p>]]></content>
<summary type="html"><p>音乐播放器测试(进来听歌)</p></summary>
<category term="测试页" scheme="http://paneersblog.github.io/categories/%E6%B5%8B%E8%AF%95%E9%A1%B5/"/>
</entry>
<entry>
<title>Python入门笔记(二)</title>
<link href="http://paneersblog.github.io/28396.html"/>
<id>http://paneersblog.github.io/28396.html</id>
<published>2022-02-07T15:31:37.000Z</published>
<updated>2022-07-16T09:28:48.139Z</updated>
<content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="/assets/css/APlayer.min.css"><script src="/assets/js/APlayer.min.js" class="aplayer-secondary-script-marker"></script><script class="meting-secondary-script-marker" src="/assets/js/Meting.min.js"></script><p>人生苦短 我用Python</p><span id="more"></span><hr><h2 id="Python中的注释"><a href="#Python中的注释" class="headerlink" title="Python中的注释"></a>Python中的注释</h2><p>什么是注释?</p><ul><li>是指程序员在代码中对代码功能解释说明的文字,可以提高代码的可读性</li><li>注释的内容将被Python解释器忽略,不被计算机执行</li></ul><p>注释的分类?</p><ul><li>单行注释<ul><li>以“#”作为单行注释的符号,作用范围从“#”开始直到换行为止</li></ul></li><li>多行注释<ul><li>Python中并没有单独的多行注释标记,将包含在一对三引号[‘’’…’’’]OR[“””…”””]之间的代码称为多行注释</li></ul></li><li>中文注释声明<ul><li># coding:utf-8 或 #coding=utf-8 或 #-*-coding:utf-8-*-</li></ul></li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 10.单行注释</span></span><br><span class="line"><span class="comment"># 要求从键盘去输入出生年份,举例:1998</span></span><br><span class="line">year = <span class="built_in">input</span>(<span class="string">'请输入您的出生年份:'</span>)</span><br><span class="line"></span><br><span class="line">year = <span class="built_in">input</span>(<span class="string">'请输入您的出生年份:'</span>) <span class="comment"># 要求从键盘去输入出生年份,举例:1998</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 11.多行注释</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="string">参考视频:马士兵教育</span></span><br><span class="line"><span class="string">分节名:11.多行注释</span></span><br><span class="line"><span class="string">创建人:Paneer</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="comment"># -*- OR -*- #</span></span><br><span class="line"><span class="string">"""</span></span><br><span class="line"><span class="string">参考视频:马士兵教育</span></span><br><span class="line"><span class="string">分节名:11.多行注释</span></span><br><span class="line"><span class="string">创建人:Paneer</span></span><br><span class="line"><span class="string">"""</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 12.中文声明注释</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 在Python2.x中,使用中文注释时必须要加上中文声明注释。在Python3.x中可加可不加。</span></span><br><span class="line"><span class="comment"># coding:utf-8</span></span><br><span class="line"><span class="comment"># 此声明若加的话务必加在代码首行。</span></span><br><span class="line"><span class="comment"># 写好注释至关重要哦~</span></span><br></pre></td></tr></table></figure><h2 id="代码缩进"><a href="#代码缩进" class="headerlink" title="代码缩进"></a>代码缩进</h2><p>Python语言采用严格的“缩进”来表示程序逻辑</p><ul><li>缩进是指每行语句开始前的空白区域,用来表示Python程序间的包含和层次关系</li><li>一般代码不需要缩进,顶行编写且不留空白</li><li>类定义、函数定义、流程控制语句,以及异常处理语句等,行尾的冒号和下一行的缩进表示一个代码块的开始,而缩进结束则表示一个代码块的结束</li><li>缩进可以使用空格或Tab键来实现,通常情况下采用四个空格作为一个缩进量</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 13.代码缩进</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'hello'</span>)</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'hello'</span>) <span class="comment">#此情况下会报错:IndentationError: unexpected indent,解决办法是删掉第二个print前的空格</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># 类的定义</span></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">Student</span>:</span><br><span class="line"> <span class="keyword">pass</span></span><br><span class="line"><span class="comment"># 函数定义</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">fun</span>():</span><br><span class="line"> <span class="keyword">pass</span></span><br></pre></td></tr></table></figure><h2 id="在Python交互式模式中运行-py文件"><a href="#在Python交互式模式中运行-py文件" class="headerlink" title="在Python交互式模式中运行*.py文件"></a>在Python交互式模式中运行*.py文件</h2><p>首先确保电脑已经安装好python且配置好了环境变量,其语法格式为:</p><figure class="highlight dos"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">python 完整文件名(包括路径)</span><br></pre></td></tr></table></figure><h2 id="数据类型和基本运算符"><a href="#数据类型和基本运算符" class="headerlink" title="数据类型和基本运算符"></a>数据类型和基本运算符</h2><h3 id="保留字与标识符"><a href="#保留字与标识符" class="headerlink" title="保留字与标识符"></a>保留字与标识符</h3><p>保留字:<br>保留字是Python已经被赋予特定意义的一些单词,在开发程序时,不可以把这些保留字作为变量、函数、类、模块和其他对象的名称来使用<br>保留字表如下所示:</p><table><thead><tr><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th><th align="center"></th></tr></thead><tbody><tr><td align="center">and</td><td align="center">as</td><td align="center">assert</td><td align="center">break</td><td align="center">class</td><td align="center">continue</td><td align="center">def</td><td align="center">del</td><td align="center">elif</td><td align="center">else</td><td align="center">except</td></tr><tr><td align="center">finally</td><td align="center">for</td><td align="center">from</td><td align="center">False</td><td align="center">global</td><td align="center">if</td><td align="center">import</td><td align="center">in</td><td align="center">is</td><td align="center">lambda</td><td align="center">nonlocal</td></tr><tr><td align="center">not</td><td align="center">None</td><td align="center">or</td><td align="center">pass</td><td align="center">raise</td><td align="center">return</td><td align="center">try</td><td align="center">True</td><td align="center">while</td><td align="center">with</td><td align="center">yield</td></tr></tbody></table><blockquote><p>注:保留字严格区分大小写,只有<strong>True</strong>、<strong>False</strong>、<strong>None</strong>为首字母大写。</p></blockquote><p>保留字查看</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 保留字的查看</span></span><br><span class="line"><span class="keyword">import</span> keyword</span><br><span class="line"><span class="built_in">print</span>(keyword.kwlist)</span><br></pre></td></tr></table></figure><p>标识符:<br>标识符可以简单的理解为是一个名字,它主要用来标识变量、函数、类、模块和其他对象的名称。 </p><blockquote><p>Python标识符的命名规则:</p><ul><li>可以是字母、下划线“_”和数字,并且第一个字符不能是数字</li><li>不能使用Python中的保留字</li><li>标识符严格区分大小写</li><li>以下划线开头的标识符有特殊意义,一般应避免使用相似的标识符</li><li>允许使用中文作为标识符,但不建议</li></ul></blockquote><p>标识符的命名规范:</p><ul><li>模块名尽量短小,并且尽量全部使用小写字母,可以使用下划线分隔多个字母。如 grame_main</li><li>包名尽量短小,并且尽量全部使用小写字母,不推荐使用下划线。如 com.paneer,不推荐com_paneer</li><li>类名采用单词首字母大写形式(Pascal风格)。如 MyClass</li><li>模块内部的类采用“_”+Pascal风格的类名组成。如在MyClass中的内部类 _InnerMyClass</li><li>函数、类的属性和方法的命名,全部使用小写字母,多个字母之间使用下划线分隔</li><li>常量命名时采用全部大写字母,可以使用下划线</li><li>使用单下划线“_”开头的模块变量或函数是受保护的,在使用<code>from xxx import *</code>语句从模块中导入时,这些模块变量或函数是不能被导入的</li><li>使用双下划线“__“开头的实例变量或方法是类私有的</li><li>以双下划线开头和结尾的是Python的专用标识。如 <code>__init__()</code> 表示初始化函数</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 2.标识符的规范</span></span><br><span class="line"></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="string">每一个*.py文件都是一个模块,模块命名应尽量使用小写字母并使用下划线分隔</span></span><br><span class="line"><span class="string">这些*.py文件所在的文件夹称作包,包命名应尽量使用小写字母不推荐使用下划线</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">class</span> <span class="title class_">MyClass</span>: <span class="comment"># 新建一个名为MyClass的类,采用Pascal风格</span></span><br><span class="line"> <span class="keyword">class</span> <span class="title class_">_InnerMyClass</span>: <span class="comment"># 新建一个名为 _InnerMyClass 的内部类</span></span><br><span class="line"> <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 函数 fun & fun_name 的定义</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">fun</span>():</span><br><span class="line"> <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">fun_name</span>():</span><br><span class="line"> <span class="keyword">pass</span></span><br></pre></td></tr></table></figure><h2 id="Python中的变量"><a href="#Python中的变量" class="headerlink" title="Python中的变量"></a>Python中的变量</h2><p>变量是指保存和表示数值的一种语法元素,可以简单的理解为“名字”。<br>变量的值是可以改变的,可以通过赋值方式被修改。</p><blockquote><p>例如,<code>word='Paneer真帅'</code>即是将“Paneer真帅”赋值给了变量“word”</p><p>可以理解为去菜鸟驿站取快递,我只需要取件码就能找到自己的快递,此时我的取件码就是一个变量,它代表的那个位置上的快递是我的,因为是菜鸟驿站的工作人员给它赋值了。</p></blockquote><h3 id="变量的定义"><a href="#变量的定义" class="headerlink" title="变量的定义"></a>变量的定义</h3><p>其语法结构为:</p><pre><code>变量名=value</code></pre><h3 id="变量的使用"><a href="#变量的使用" class="headerlink" title="变量的使用"></a>变量的使用</h3><p>Python是一种动态类型的语言,变量的类型可以随时变化</p><ul><li>使用内置函数<code>type()</code>可以查看变量的数据类型</li></ul><p>Python中允许多个变量指向同一个值</p><ul><li>使用内置函数<code>id()</code>可以返回变量所指的内存地址</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 3.变量的定义和使用</span></span><br><span class="line">luck_number=<span class="number">8</span> <span class="comment"># 创建一个整型变量luck_number,赋值为8</span></span><br><span class="line">my_name=<span class="string">'Paneer'</span> <span class="comment"># 创建一个字符串类型变量</span></span><br><span class="line"><span class="built_in">print</span>(my_name,<span class="string">'的幸运数字是:'</span>,luck_number)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'luck_number的数据类型是:'</span>,<span class="built_in">type</span>(luck_number))</span><br><span class="line"></span><br><span class="line"><span class="comment"># 变量的值可以更改</span></span><br><span class="line">luck_number=<span class="string">'Emily真圆'</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'luck_number的数据类型是:'</span>,<span class="built_in">type</span>(luck_number)) <span class="comment"># 此时其数据类型就是 str型(字符串型)了</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Python允许多个变量指向同一个值</span></span><br><span class="line">no=number=<span class="number">502</span> <span class="comment"># 给no 和number 都赋值为502</span></span><br><span class="line"><span class="built_in">print</span>(no,number)</span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">id</span>(no)) <span class="comment"># 输出no 所指向的内存地址</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">id</span>(number)) <span class="comment">#输出number 所指向的内存地址,会发现与no 的相同</span></span><br></pre></td></tr></table></figure><p>变量命名应遵循以下几条规则</p><blockquote><ul><li>变量名必须是一个有效的标识符</li><li>变量名不能使用Python中的保留字</li><li>慎用小写字母l和大写字母O</li><li>应选择有意义的单词作为变量名</li></ul></blockquote><p>同样的,常量也应遵循以下规则</p><blockquote><ul><li>常量就是在程序运行过程中值不能改变的量。如PI</li><li>Python中没有定义常量的保留字</li><li>常量规定使用大写字母和下划线组成</li><li>常量首次赋值之后,还是可以被其他代码修改的</li></ul></blockquote><h2 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h2><h3 id="数值类型"><a href="#数值类型" class="headerlink" title="数值类型"></a>数值类型</h3><h4 id="整数类型特点"><a href="#整数类型特点" class="headerlink" title="整数类型特点"></a>整数类型特点</h4><ul><li>表示整数数值,即没有小数部分的数值</li><li>正整数、负数和0</li><li>理论取值范围为(负无穷,正无穷)</li><li>整数的表示类型</li><li>不可变的数据类型</li></ul><table><thead><tr><th align="center">进制种类</th><th align="center">引导符号</th><th align="center">概述</th></tr></thead><tbody><tr><td align="center">十进制</td><td align="center">无</td><td align="center">默认情况,如 365,257</td></tr><tr><td align="center">二进制</td><td align="center">0b或0B</td><td align="center">由0,1组成,如 0b101,0B1010</td></tr><tr><td align="center">八进制</td><td align="center">0o或0O</td><td align="center">由0-7组成,如 0o367,0O666</td></tr><tr><td align="center">十六进制</td><td align="center">0x或0X</td><td align="center">由0-9,a(A)-f(F)组成,如 0x98A,0X89F</td></tr></tbody></table><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 4.整数类型</span></span><br><span class="line">num=<span class="number">987</span> <span class="comment"># 默认十进制</span></span><br><span class="line">num1=<span class="number">0b10100101</span> <span class="comment"># 使用二进制表示整数</span></span><br><span class="line">num2=<span class="number">0o765</span> <span class="comment"># 使用八进制表示整数</span></span><br><span class="line">num3=<span class="number">0x98AF</span> <span class="comment"># 使用十六进制表示整数</span></span><br><span class="line"><span class="built_in">print</span>(num) <span class="comment"># 输出全部为十进制</span></span><br><span class="line"><span class="built_in">print</span>(num1) <span class="comment"># 输出全部为十进制</span></span><br><span class="line"><span class="built_in">print</span>(num2) <span class="comment"># 输出全部为十进制</span></span><br><span class="line"><span class="built_in">print</span>(num3) <span class="comment"># 输出全部为十进制</span></span><br></pre></td></tr></table></figure><h4 id="浮点数类型"><a href="#浮点数类型" class="headerlink" title="浮点数类型"></a>浮点数类型</h4><ul><li>表示带有小数点的数</li><li>浮点数由整数部分和小数部分组成</li><li>Python中浮点数类型必须要有小数部分,小数部分可以是0</li><li>浮点数可以使用科学计数法表示</li><li>两个浮点数相加,有一定概率运算结果后增加一些“不确定的”尾数</li><li>使用内置函数<code>round()</code>可以限定运算结果需要保留的小数位数</li><li>不可变数据类型</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 5.浮点数类型</span></span><br><span class="line">height=<span class="number">180.1</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(height)) <span class="comment"># 可以得出height 的数据类型为float 型</span></span><br><span class="line">x=<span class="number">10</span></span><br><span class="line">y=<span class="number">10.0</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(x)) <span class="comment"># x为int 型</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(y)) <span class="comment"># y为float 型</span></span><br><span class="line"><span class="comment"># 浮点数相加尾数不确定问题</span></span><br><span class="line"><span class="built_in">print</span>(<span class="number">0.1</span>+<span class="number">0.2</span>) <span class="comment"># 得结果为 0.30000000000000004,有一不确定尾数</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">round</span>(<span class="number">0.1</span>+<span class="number">0.2</span>,<span class="number">1</span>)) <span class="comment"># 保留一位小数</span></span><br></pre></td></tr></table></figure><h4 id="复数类型"><a href="#复数类型" class="headerlink" title="复数类型"></a>复数类型</h4><ul><li>Python中复数与数学中的复数形式完全一致</li><li>复数由实部和虚部组成</li><li>j是复数的一个基本单位,被定义为 j=$\sqrt{-1}$ ,又称虚数单位</li><li><code>.real</code>获取实数部分,<code>.imag</code>获取虚数部分</li><li>不可变数据类型</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 6.复数类型</span></span><br><span class="line">z=<span class="number">123</span>+<span class="number">456j</span> <span class="comment"># 定义复数类型 complex型</span></span><br><span class="line"><span class="built_in">print</span>(<span class="built_in">type</span>(z))</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'实数部分:'</span>,z.real) <span class="comment"># 输出实数部分</span></span><br><span class="line"><span class="built_in">print</span>(<span class="string">'虚数部分:'</span>,z.imag) <span class="comment"># 输出虚数部分</span></span><br></pre></td></tr></table></figure><h4 id="字符串类型"><a href="#字符串类型" class="headerlink" title="字符串类型"></a>字符串类型</h4><ul><li>字符串就是连续的字符序列,,可以表示计算机所能识别的一切字符</li><li>不可变数据类型,,即不可变字符序列</li><li>单行字符串使用’…’或”…”</li><li>多行字符串使用’’’…’’’或”””…”””</li></ul><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 7.字符串类型</span></span><br><span class="line"><span class="comment"># 单行字符串</span></span><br><span class="line">city=<span class="string">'菏泽'</span></span><br><span class="line">address=<span class="string">"山东省菏泽市"</span></span><br><span class="line"><span class="built_in">print</span>(city)</span><br><span class="line"><span class="built_in">print</span>(address)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 多行字符串</span></span><br><span class="line">info=<span class="string">'''</span></span><br><span class="line"><span class="string">地址:山东省菏泽市</span></span><br><span class="line"><span class="string">收件人:Paneer</span></span><br><span class="line"><span class="string">'''</span></span><br><span class="line"><span class="built_in">print</span>(info)</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><p>人生苦短 我用Python</p></summary>
<category term="编程语言" scheme="http://paneersblog.github.io/categories/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/"/>
<category term="Python" scheme="http://paneersblog.github.io/tags/Python/"/>
</entry>
</feed>