-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
3002 lines (1323 loc) · 151 KB
/
index.html
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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="theme-next pisces" lang="zh-CN">
<head><meta name="generator" content="Hexo 3.8.0">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2">
<link rel="stylesheet" href="/css/main.css?v=7.0.0">
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.0.0">
<link rel="icon" type="image/png" sizes="32x32" href="http://pndcgm4gq.bkt.clouddn.com/%E7%BD%91%E7%AB%99%E5%9B%BE%E6%A0%87.png?v=7.0.0">
<link rel="icon" type="image/png" sizes="16x16" href="http://pndcgm4gq.bkt.clouddn.com/%E7%BD%91%E7%AB%99%E5%9B%BE%E6%A0%87.png?v=7.0.0">
<link rel="mask-icon" href="/images/logo.svg?v=7.0.0" color="#222">
<meta property="fb:admins" content="<user_id>">
<meta property="fb:app_id" content="<app_id>">
<script id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Pisces',
version: '7.0.0',
sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false,"dimmer":false},
fancybox: false,
fastclick: false,
lazyload: false,
tabs: true,
motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<meta name="description" content="学习python编程的python小白">
<meta property="og:type" content="website">
<meta property="og:title" content="欢迎来到这里">
<meta property="og:url" content="LittleMaoer.github.io/index.html">
<meta property="og:site_name" content="欢迎来到这里">
<meta property="og:description" content="学习python编程的python小白">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="欢迎来到这里">
<meta name="twitter:description" content="学习python编程的python小白">
<link rel="canonical" href="LittleMaoer.github.io/">
<script id="page.configurations">
CONFIG.page = {
sidebar: "",
};
</script>
<title>欢迎来到这里</title>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<app_id>',
xfbml : true,
version: 'v2.10'
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/zh_CN/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<noscript>
<style>
.use-motion .motion-element,
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-title { opacity: initial; }
.use-motion .logo,
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
<div class="container sidebar-position-left
page-home">
<div class="headband"></div>
<a href="https://github.com/LittleMaoer" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewbox="0 0 250 250" style="fill:#fff; color:#151513; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"/><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"/><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"/></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">欢迎来到这里</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
<p class="site-subtitle">—— 茂茂</p>
</div>
<div class="site-nav-toggle">
<button aria-label="切换导航栏">
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-home menu-item-active">
<a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i> <br>首页</a>
</li>
<li class="menu-item menu-item-about">
<a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i> <br>关于</a>
</li>
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br>标签</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br>分类</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br>归档</a>
</li>
<li class="menu-item menu-item-search">
<a href="javascript:;" class="popup-trigger">
<i class="menu-item-icon fa fa-search fa-fw"></i> <br>搜索</a>
</li>
</ul>
<div class="site-search">
<div class="popup search-popup local-search-popup">
<div class="local-search-header clearfix">
<span class="search-icon">
<i class="fa fa-search"></i>
</span>
<span class="popup-btn-close">
<i class="fa fa-times-circle"></i>
</span>
<div class="local-search-input-wrapper">
<input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
</div>
</div>
<div id="local-search-result"></div>
</div>
</div>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<section id="posts" class="posts-expand">
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="LittleMaoer.github.io/2019/03/02/Python学习框架/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="高盛茂">
<meta itemprop="description" content="学习python编程的python小白">
<meta itemprop="image" content="http://pndcgm4gq.bkt.clouddn.com/%E5%A4%B4%E5%83%8F.jpg">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="欢迎来到这里">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2019/03/02/Python学习框架/" class="post-title-link" itemprop="url">python学习框架</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2019-03-02 11:39:51 / 修改时间:12:18:52" itemprop="dateCreated datePublished" datetime="2019-03-02T11:39:51+08:00">2019-03-02</time>
</span>
<span class="post-category">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/python/" itemprop="url" rel="index"><span itemprop="name">python</span></a></span>
,
<span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/python/学习框架/" itemprop="url" rel="index"><span itemprop="name">学习框架</span></a></span>
</span>
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">评论数:</span>
<a href="/2019/03/02/Python学习框架/#comments" itemprop="discussionUrl">
<span class="post-comments-count fb-comments-count" data-href="LittleMaoer.github.io/2019/03/02/Python学习框架/" itemprop="commentCount">0</span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<figure class="highlight plain"><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><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br></pre></td><td class="code"><pre><span class="line">Python学习框架</span><br><span class="line">1.注释:#、''' '''、 """ """</span><br><span class="line">2.标识符</span><br><span class="line">3.关键字</span><br><span class="line">4.数据类型:int、float、complex、bool、str</span><br><span class="line"> 查看类型type(),判断是否是指定类型isinstance(数据,类型)</span><br><span class="line">5.缩进</span><br><span class="line">6.print函数和input函数</span><br><span class="line">7.声明一个或多个变量、变量互换:a,b=b,a</span><br><span class="line">8.运算符: a.数学运算符:+、-、*、/、//、%、**</span><br><span class="line"> b.比较运算符:>、<、>=、<=、!=、== (补充is)</span><br><span class="line"> c.逻辑运算符:and、or、not</span><br><span class="line"> d.赋值运算符:=、+=、-=、*=、/=、//=、%=、**=</span><br><span class="line"> 优先级:数字>比较>逻辑>赋值</span><br><span class="line">9.数字类型:a.int</span><br><span class="line"> b.float</span><br><span class="line"> c.bool</span><br><span class="line"> d.complex</span><br><span class="line">10.字符串:分类:a.普通字符</span><br><span class="line"> b.转义字符 \</span><br><span class="line"> c.编码字符 \u****</span><br><span class="line"> d.字符编码:chr(编码值) - 获取字符</span><br><span class="line"> ord(字符) - 获取编码</span><br><span class="line"> 内建函数:1)字符串.capitalize()</span><br><span class="line"> 2)字符串.center(width,fillchar)</span><br><span class="line"> 3)字符串1.count(字符串2)</span><br><span class="line"> 4) 字符串1.endwith(字符串2,start,end)</span><br><span class="line"> 5) 字符串.expandtabs(tabsize)</span><br><span class="line"> 6) 字符串1.find(字符串2,beg,end)</span><br><span class="line"> 7)字符串1.index(字符串2,beg,end)</span><br><span class="line"> 8)字符串1.isalnum()</span><br><span class="line"> 9)字符串.isalpha()</span><br><span class="line"> 10)字符串.isdigit()</span><br><span class="line"> 11) 字符串.idlower()</span><br><span class="line"> 12) 字符串.isnumeric()</span><br><span class="line"> 13)字符串.isspace()</span><br><span class="line"> 14) 字符串.istitle()</span><br><span class="line"> 15) 字符串.isupper()</span><br><span class="line"> 16) 字符串1.join(字符串2)</span><br><span class="line"> 17) len(字符串)</span><br><span class="line"> 18) 字符串1.ljust(width,fillchar)</span><br><span class="line"> 19) 字符串.lower()</span><br><span class="line"> 20) 字符串.lstrip()</span><br><span class="line"> 21) max()</span><br><span class="line"> 22) min()</span><br><span class="line"> 23) 字符串.replace(old,new,max)</span><br><span class="line"> 24)字符串1.rfind(字符串2,beg,end)</span><br><span class="line"> 25) 字符串.rjust(width,fillchar)</span><br><span class="line"> 26) 字符串.rstrip()</span><br><span class="line"> 27) 字符串1.split(字符串2,num)</span><br><span class="line"> 28) 字符串1.startswith(字符串2,beg,end)</span><br><span class="line"> 29) 字符串.strip()</span><br><span class="line"> 30) 字符串.swapcase</span><br><span class="line"> 31) 字符串.title()</span><br><span class="line"> 32) 字符串.upper()</span><br><span class="line"> 33) 字符串.zfill(width)</span><br><span class="line"> 34) 字符串.isdecimal()</span><br><span class="line"> 获取字符串:字符串[下标]、字符串[开始下标:结束下标:步长]</span><br><span class="line"> 字符串运算符:+、*、>、<、==、!=、>=、<=</span><br><span class="line"> in 和 not in 操作</span><br><span class="line"> len(序列)</span><br><span class="line"> 格式字符串:占位符 % (值1, 值2,...)</span><br><span class="line"> 占位符:%s、%d、%f或%nf、%c、%u、%o、%x、%X、%e、%E、%g、%G</span><br><span class="line"> 类型转换:int(数据)、float(数据)、bool(数据)、str()</span><br><span class="line">11.语法:a.条件语句:什么时候使用,语法,执行过程,</span><br><span class="line"> if结构、if-else结构、if-elif-else结构、</span><br><span class="line"> 值1 if 表达式 else 值2</span><br><span class="line"> b.循环语句:for循环和while循环</span><br><span class="line"> range() 注意:最后的取不到</span><br><span class="line"> continue、break、break...else</span><br><span class="line">12.列表list:a.定义:可变,有序</span><br><span class="line"> b.字面量:[2,3,6...]</span><br><span class="line"> c.获取元素:列表[下标]、列表[开始下标,结束下标,步长]、for循环遍历</span><br><span class="line"> d.增:列表.append(元素)</span><br><span class="line"> 列表.insert(下标,元素)</span><br><span class="line"> 删:del 列表(下标)</span><br><span class="line"> 列表.remove(元素)</span><br><span class="line"> 列表.pop(下标)</span><br><span class="line"> 坑:1)遍历列表元素删不全:切片删</span><br><span class="line"> 2)遍历列表下标下标越界删不全:下标元素删除的下标值不懂;不删的下标+1</span><br><span class="line"> e.改:列表[下标] = 新值</span><br><span class="line"> f.运算符:+、*、比较运算符、in和not in</span><br><span class="line"> g.类型转换:list()</span><br><span class="line"> h.取长度:len(列表)</span><br><span class="line"> i.max(序列)、min(序列)、sum(序列)</span><br><span class="line"> j.内建函数:1) list.append(对象)</span><br><span class="line"> 2)list.count(元素)</span><br><span class="line"> 3) list.extend(序列)</span><br><span class="line"> 4) list.index(元素)</span><br><span class="line"> 5)list.insert(index,对象)</span><br><span class="line"> 6)list.pop([index=-1])</span><br><span class="line"> 7)list.remove(元素)</span><br><span class="line"> 8)list.reverse()</span><br><span class="line"> 9) list.sort(cmp=None,key=None,reverse=False)</span><br><span class="line"> 10) list.clear()</span><br><span class="line"> 11) list.copy()</span><br><span class="line">13.元祖(tuple):a.定义(不可变,有序)</span><br><span class="line"> b.字面量:(2,4,6),</span><br><span class="line"> ()空元祖、(3,)只有一个元素的元祖</span><br><span class="line"> c.获取元素:1)元祖[下标]</span><br><span class="line"> 2)元素[:]</span><br><span class="line"> 3)遍历</span><br><span class="line"> 4)变量1,变量2..=元祖</span><br><span class="line"> 变量1,*变量2 =元祖</span><br><span class="line"> d.相关运算:+、*、in/not in、len()、max()、min()、sum()</span><br><span class="line"> e.排序:sorted(序列) - 不管什么序列排完都是产生一个新的列表</span><br><span class="line"> 列表.sort() - 修改原列表中元素的排序</span><br><span class="line">14.字典(dict):a.定义:可变,无序</span><br><span class="line"> b.字面量:{key1:value1,key2:value2...}</span><br><span class="line"> key:唯一,不可变</span><br><span class="line"> c.什么时候使用字典</span><br><span class="line"> d.获取值:字典[key]-key不存在会报错</span><br><span class="line"> 字典.get(key)-key不存在会取得None</span><br><span class="line"> 字典.get(key,值1)-key不存在会取得值1</span><br><span class="line"> 遍历字典取得key值,利用key值取value</span><br><span class="line"> 遍历字典的values(),获取所有值(不建议使用)</span><br><span class="line"> 遍历字典的items(),获取所有key和value(不建议使用)</span><br><span class="line"> 增/改加值:字典[key]=值</span><br><span class="line"> 删:del 字典[key]</span><br><span class="line"> 字典.pop(key)</span><br><span class="line"> f.相关运算:==、!=、in、not in、len()、max()、min()</span><br><span class="line"> g.相关方法:1)字典.clear()</span><br><span class="line"> 2) 字典.copy() - 产生一个新的字典</span><br><span class="line"> 3) 字典.fromkeys(序列,值)</span><br><span class="line"> 4)字典.keys()</span><br><span class="line"> 5) 字典.values()</span><br><span class="line"> 6)字典.items()</span><br><span class="line"> 7)字典.setdefault(key,value=None)</span><br><span class="line"> 8) 字典.update(字典2)</span><br><span class="line">15.集合(set):a.定义:可变,无序,元素唯一</span><br><span class="line"> b.字面量:{元素1,元素2,元素3,...}</span><br><span class="line"> c.查元素:遍历</span><br><span class="line"> 增加元素:集合.add(元素)</span><br><span class="line"> 集合.update(元素)</span><br><span class="line"> 集合.remove()</span><br><span class="line"> d.运算:&、|、-、^</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">.进制:二进制:0b/B+二进制数;转换成二进制数:bin(其他进制)</span><br><span class="line"> 八进制: 0o/O+八进制数;转换成八进制数:oct(其他进制)</span><br><span class="line"> 十六进制: 0x/X+十六进制数;转换成十六进制数:hex(其他进制)</span><br><span class="line"> 原码:符号位(0代表正数,1代表负数)+真值</span><br><span class="line"> 反码:正数的反码还是原码;负数的反码符号位不变,其他位取反(1和0互换)</span><br><span class="line"> 补码:正数的补码还是原码;负数的补码是反码+1</span><br><span class="line"> 为什么存补码(计算机中只有加法器,没有加法器)</span><br><span class="line"> 位运算:&(与1与判断奇偶)、|(与1或置1)、~、^(判断两个数是否相同)、>>(除以2的n次方)、<<</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="LittleMaoer.github.io/2019/03/02/vim编辑器之神/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="高盛茂">
<meta itemprop="description" content="学习python编程的python小白">
<meta itemprop="image" content="http://pndcgm4gq.bkt.clouddn.com/%E5%A4%B4%E5%83%8F.jpg">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="欢迎来到这里">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2019/03/02/vim编辑器之神/" class="post-title-link" itemprop="url">vim编辑器文件操作指令</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2019-03-02 09:39:16 / 修改时间:09:47:38" itemprop="dateCreated datePublished" datetime="2019-03-02T09:39:16+08:00">2019-03-02</time>
</span>
<span class="post-category">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/vim编辑/" itemprop="url" rel="index"><span itemprop="name">vim编辑</span></a></span>
,
<span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/vim编辑/文件操作命令/" itemprop="url" rel="index"><span itemprop="name">文件操作命令</span></a></span>
</span>
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">评论数:</span>
<a href="/2019/03/02/vim编辑器之神/#comments" itemprop="discussionUrl">
<span class="post-comments-count fb-comments-count" data-href="LittleMaoer.github.io/2019/03/02/vim编辑器之神/" itemprop="commentCount">0</span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<figure class="highlight plain"><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></pre></td><td class="code"><pre><span class="line"># vim编辑器之神</span><br><span class="line">### 配置vimrc配置</span><br><span class="line">在shell中可以通过 `vim ~/.vimrc` 或者 `vim /etc/vimrc` 打开vimrc文件对vim进行配置。在这个文件中可以进行很多和vim相关的配置,常用的如下(如果对其他配置感兴趣的可以自己百度):</span><br><span class="line"></span><br><span class="line">![](./img/vim1.png) </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">### 常用操作</span><br><span class="line">#### 1.模式切换</span><br><span class="line">我们可以将vim分为命令模式、编辑模式和末行模式三种 </span><br><span class="line">**命令模式:**进入vim的时候vim是处于命令模式状态下的,这个时候输入内容不会出现在编辑区 (最末什么都没有)</span><br><span class="line"></span><br><span class="line">**末行模式:**在命令模式下输入冒号,让vim进入末行模式。在末行模式的冒号后面可以输入相关的一些指令进行相关操作 (最后有一个冒号)</span><br><span class="line"></span><br><span class="line">**编辑模式:**在命令模式下按'i'进入编辑模式。在编辑模式下可以对文件内容进行编辑 (最后 --INSERT-- 或者 --插入--) </span><br><span class="line"></span><br><span class="line">####2.保存和退出</span><br><span class="line">在末行模式下输入相应的指令可以对编辑区的内容进行保存和退出vim界面 </span><br><span class="line">**w** -- 只保存(类似快捷键ctr+s) </span><br><span class="line">**q** -- 退出(在编辑区的内容全部都保存的情况下才有效) </span><br><span class="line">**wq** -- 保存并退出 </span><br><span class="line">**q!** -- 强制退出(不保存修改信息) </span><br><span class="line"></span><br><span class="line">####3.光标操作 </span><br><span class="line">以下光标操作都是在命令模式下输入的 </span><br><span class="line">**^(shift+6)** -- 移动到行首 </span><br><span class="line">**$(shift+4)** -- 移动到行尾 </span><br><span class="line">**G(shift+g)** -- 移动到文件末尾</span><br><span class="line">**行号G** -- 移动到指定行,例如:30G, 让光标直接跳转到行号是30的那一行</span><br><span class="line">**gg** -- 移动到文件开头 </span><br><span class="line"></span><br><span class="line">####4.文本操作 </span><br><span class="line">以下操作不带冒号的是在命令模式下输入,前面有冒号代码后面的内容是在末行模式下输入 </span><br><span class="line">**dd** -- 删除光标所在的行 </span><br><span class="line">**数字dd** -- 从光标所在行开始往后面开始删,删除指定数量行内容 </span><br><span class="line">**:%d** -- 删除所有 </span><br><span class="line"></span><br><span class="line">**yy** -- 复制光标所在的行 </span><br><span class="line">**数字yy** -- 从光标所在行开始复制指定行数的内容 </span><br><span class="line">**p** -- 将复制的内容粘贴到光标所在的位置 </span><br><span class="line">**u** -- 撤销 </span><br><span class="line">**ctr+r** -- 反撤销 </span><br><span class="line"></span><br><span class="line">**:%!sort** -- 对内容排序(将一行内容看出一个字符串然后按照字符串大小进行排序) </span><br><span class="line">**:/正则表达式** -- 搜索匹配正则表达式的内容,按回车回到命令模式后按n往前查找,按N往后查找 </span><br><span class="line">**:/查找对象[/gice]** -- 搜索匹配正则表达式的内容,按回车回到命令模式后按n往前查找,按N往后查找 </span><br><span class="line">注意:正则表达式除了表示次数的符号前需要加\,别的和python是一样的。例如:</span><br><span class="line">'''</span><br><span class="line">:/\d\{2} -> 查找两个数字</span><br><span class="line">:/a\+ -> 查找a出现一次或者多次</span><br><span class="line">'''</span><br><span class="line"></span><br><span class="line">**:1,$s/被替换对象/替换内容/参数** -- 将正则表达式匹配到的内容替换成指定内容 </span><br><span class="line"></span><br><span class="line"> - g: 全局匹配 </span><br><span class="line"> - i: 忽略大小写 </span><br><span class="line"> - c: 替换时需要提示 </span><br><span class="line"> - e: 忽略错误</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="LittleMaoer.github.io/2019/02/26/MySQL基本操作指令/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="高盛茂">
<meta itemprop="description" content="学习python编程的python小白">
<meta itemprop="image" content="http://pndcgm4gq.bkt.clouddn.com/%E5%A4%B4%E5%83%8F.jpg">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="欢迎来到这里">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2019/02/26/MySQL基本操作指令/" class="post-title-link" itemprop="url">MySQL数据库基本操作指令</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2019-02-26 21:04:42" itemprop="dateCreated datePublished" datetime="2019-02-26T21:04:42+08:00">2019-02-26</time>
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-calendar-check-o"></i>
</span>
<span class="post-meta-item-text">更新于</span>
<time title="修改时间:2019-02-27 21:47:11" itemprop="dateModified" datetime="2019-02-27T21:47:11+08:00">2019-02-27</time>
</span>
<span class="post-category">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-folder-o"></i>
</span>
<span class="post-meta-item-text">分类于</span>
<span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/MySQL数据库/" itemprop="url" rel="index"><span itemprop="name">MySQL数据库</span></a></span>
,
<span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/MySQL数据库/基本操作指令/" itemprop="url" rel="index"><span itemprop="name">基本操作指令</span></a></span>
</span>
<span class="post-comments-count">
<span class="post-meta-divider">|</span>
<span class="post-meta-item-icon">
<i class="fa fa-comment-o"></i>
</span>
<span class="post-meta-item-text">评论数:</span>
<a href="/2019/02/26/MySQL基本操作指令/#comments" itemprop="discussionUrl">
<span class="post-comments-count fb-comments-count" data-href="LittleMaoer.github.io/2019/02/26/MySQL基本操作指令/" itemprop="commentCount">0</span>
</a>
</span>
</div>
</header>
<div class="post-body" itemprop="articleBody">
<figure class="highlight plain"><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><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br></pre></td><td class="code"><pre><span class="line">数据库排名:</span><br><span class="line">Oracle(关系型) </span><br><span class="line">MySQL(关系型) </span><br><span class="line">SQLServer(关系型) </span><br><span class="line">PostgreSQL(关系型) </span><br><span class="line">MongoDB(非关系数据库) </span><br><span class="line">DB2(关系型) </span><br><span class="line">Redis(非关系数据库) </span><br><span class="line">ElasticSearch(非关系数据库) </span><br><span class="line"></span><br><span class="line">行(记录)</span><br><span class="line">列(字段)</span><br><span class="line"></span><br><span class="line">关系型数据库:想</span><br><span class="line"></span><br><span class="line">SQL语句(结构化查询语言) </span><br><span class="line">DDL(数据定义语言): create / drop / alter </span><br><span class="line">DML(数据操作语言 - Data Manipulation Language): insert / delete / update / select </span><br><span class="line">DCL(数据控制语言): grant / revoke </span><br><span class="line"></span><br><span class="line">-- 注意: SQL中大小写不敏感(大写和小写是一样的); 每条SQL语句必须以分号结束</span><br><span class="line"></span><br><span class="line">-- 一.DDL - 主要提供数据库和表的创建、删除和修改 </span><br><span class="line">-- 0. 删除数据库: drop database 数据库名;</span><br><span class="line">DROP DATABASE school; -- 直接删除指定数据库</span><br><span class="line">DROP DATABASE if EXISTS school; -- 如果指定的数据库存在就删除数据库</span><br><span class="line"></span><br><span class="line">-- 1.创建数据库: create database 数据库名;</span><br><span class="line">create database school; -- 直接创建指定数据库</span><br><span class="line">CREATE database if not EXISTS school; -- 当指定数据库不存在的时候才创建数据库</span><br><span class="line">create database if not EXISTS school default charset utf8; -- 创建数据库的时候设置字符集编码方式为utf8,让数据库支持中文数据的存储</span><br><span class="line"></span><br><span class="line">-- 2.使用/切换数据库: use 数据库名;</span><br><span class="line">use school;</span><br><span class="line"></span><br><span class="line">-- 3.新建表: create table if not exists 表名(字段名1 类型1, 字段2 类型2,...);</span><br><span class="line">-- 注意: a. 表名一般需要加前缀't'或者'tb' b.字段用来确定表中要存储哪些数据,字段名随便命名但是不能是关键字 c.数据类型必须是MySQL支持的数据类型</span><br><span class="line">-- 常用数据类型: int-整数, char(size)-定长字符串, varchar(size)-不定长字符串, text-字符串, bit-布尔, date-日期</span><br><span class="line">CREATE TABLE if not EXISTS t_student(stuid int, stuname varchar(20), gender bit, birth date); </span><br><span class="line"></span><br><span class="line">-- 新建表并且添加约束: create table if not exists 表名(字段名1 类型1 约束1, 字段2 类型2 约束2,...);</span><br><span class="line">-- 常见约束: not null - 不为空, default - 设置默认值, unique - 值唯一, primary key - 主键约束 </span><br><span class="line">-- 主键约束: 主键的值可以确定列表中唯一一条记录(通过一个主键值可以找到表中的唯一一条记录)</span><br><span class="line">-- 注意: auto_increment只针对主键有效,并且主键的类型是整型;</span><br><span class="line">CREATE TABLE if not EXISTS t_student</span><br><span class="line">(</span><br><span class="line">stuid int not null auto_increment, </span><br><span class="line">stuname varchar(20) not null, </span><br><span class="line">gender bit DEFAULT 1, </span><br><span class="line">birth date,</span><br><span class="line">PRIMARY KEY(stuid) -- 将字段stuid作为当前表的主键(设置主键可以间接约束这个字段的值是唯一的)</span><br><span class="line">);</span><br><span class="line"> </span><br><span class="line"></span><br><span class="line">-- 4.删除表: DROP TABLE if EXISTS 表名;</span><br><span class="line">DROP TABLE if EXISTS t_student; </span><br><span class="line">-- 清空表中的数据: TRUNCATE TABLE 表名;</span><br><span class="line">TRUNCATE TABLE t_student;</span><br><span class="line"></span><br><span class="line">-- 5.修改表</span><br><span class="line">-- 5.1 添加列: alter TABLE 表名 add COLUMN 字段名 字段类型 约束;</span><br><span class="line">alter TABLE t_student add COLUMN score FLOAT(8,2) DEFAULT 0;</span><br><span class="line"></span><br><span class="line">-- 5.2 删除列: alter TABLE 表名 drop COLUMN 字段名;</span><br><span class="line">alter TABLE t_student drop COLUMN gender;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- 二、DML(数据操作语言) - 主要针对数据库中数据的增、删、改、查</span><br><span class="line">-- 1.增(添加数据/记录)</span><br><span class="line">-- 1.1插入数据/记录: insert into 表名 values(值1, 值2, 值3,....) - 依次给指定表中的字段赋值</span><br><span class="line">INSERT into t_student VALUES(100, '张三', 0, '2019-9-23');</span><br><span class="line"></span><br><span class="line">-- 1.2插入数据/记录: insert into 表名(字段名1,字段名2,...) values(值1, 值2,...) -以指定的顺序给指定的字段赋值 </span><br><span class="line">INSERT into t_student(stuname, birth) VALUES("小花", date(now())); -- 一次插入一条记录</span><br><span class="line"></span><br><span class="line">-- 一次插入多条记录</span><br><span class="line">INSERT into t_student(stuname, birth) VALUES</span><br><span class="line">("小花", date(now())),</span><br><span class="line">('小明', '2018-9-8'),</span><br><span class="line">('路飞', '1999-12-16'),</span><br><span class="line">('佐助', '2000-10-12');</span><br><span class="line"></span><br><span class="line">-- 值的问题: sql中是数字对应的值直接写,字符串需要使用引号引起来,bit类型的值只有0或者1, 时间可以用内容是满足时间格式字符串也可以是通过时间函数获取的值</span><br><span class="line">-- 时间函数: now() - 当前时间 date(now()) - 当前日期 year(now()) - 当前年 month(now()) - 当前月 .... </span><br><span class="line"></span><br><span class="line">-- 2.删(删除数据/记录) </span><br><span class="line">-- delete from 表名; - 删除指定表中所有记录</span><br><span class="line">DELETE FROM t_student;</span><br><span class="line"></span><br><span class="line">-- delete from 表名 where 条件语句; - 删除满足条件的记录 </span><br><span class="line">-- SQL中的条件语句: =(判断是否相等), <>(不等于,和python中的!=功能一样), >, <, >=, <=</span><br><span class="line">DELETE FROM t_student WHERE stuid=100; -- 删除t_student表中stuid的值等于100的记录 </span><br><span class="line">DELETE FROM t_student WHERE stuname='小花'; -- 删除t_student表中stuname的值等于'小花'的记录</span><br><span class="line">DELETE FROM t_student WHERE stuid<108; -- 删除t_student表中stuid的值小于'小花'的记录 </span><br><span class="line"></span><br><span class="line">-- 3.改(修改数据/记录) </span><br><span class="line">-- update 表名 set 字段1=新值1, 字段2=新值2,...; - 将指定表中所有行的指定列/字段的值赋值为新值</span><br><span class="line">UPDATE t_student set birth='1999-10-1', gender=1;</span><br><span class="line"></span><br><span class="line">-- update 表名 set 字段1=新值1, 字段2=新值2,... where 条件语句; -将表中满足条件的行中指定字段的值赋值为新值 </span><br><span class="line">UPDATE t_student set gender=0 WHERE stuname='小花';</span><br><span class="line"></span><br><span class="line">-- 通配符%: 表示任意个数的任意字符(包括0个)</span><br><span class="line">UPDATE t_student set birth='2000-01-01' WHERE stuname LIKE '小%'; -- 修改stuname是以'小'开头的行对应的birth的值</span><br><span class="line">UPDATE t_student set birth='2111-01-01' WHERE stuname LIKE '%小%'; </span><br><span class="line">-- 统配符_: 表示一个任意字符</span><br><span class="line">UPDATE t_student set birth='2444-01-01' WHERE stuname LIKE '小_'; -- 修改stuname只有两个字符,并且第一个字符是‘小’对应的行的birth的值</span><br><span class="line">-- 注意: 通配符只针对字符串有效! </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- 4.查(获取数据)</span><br><span class="line">-- 4.1直接查询</span><br><span class="line">-- select * from 表名; - 获取指定表中所有行和所有的列(所有数据)</span><br><span class="line">SELECT * FROM t_student;</span><br><span class="line"></span><br><span class="line">-- select 字段名1,字段名2,... from 表名; - 获取指定表中所有行指定的列 </span><br><span class="line">SELECT stuname,stuid FROM t_student; </span><br><span class="line"></span><br><span class="line">-- select * from 表名 where 条件; - 获取指定表中所有满足条件的行所有列的数据 </span><br><span class="line">SELECT * FROM t_student WHERE stuid>115; </span><br><span class="line"></span><br><span class="line">-- 4.2列重命名</span><br><span class="line">-- select 字段1 as 新字段1, 字段2 as 新字段2,... from 表名;</span><br><span class="line">-- 注意: 这儿的as可以省略</span><br><span class="line">SELECT stuid as '学号', stuname, gender as '性别' FROM t_student; -- 对查询结果中的stuid和gender字段进行重命名</span><br><span class="line"></span><br><span class="line">-- 4.3对查询结果重新赋值(一般针对布尔数据)</span><br><span class="line">-- select if(字段名,值1,值2) from 表名; -查询指定字段,并且判断字段对应的值是0还是1,如果是1结果为值1,否则为值2</span><br><span class="line">-- 注意: 这儿的if的用法是MySQL专有的</span><br><span class="line">-- MySQL写法: if(字段, 新值1, 新值2)</span><br><span class="line">SELECT stuname,if(gender,'男','女') as '性别' FROM t_student; </span><br><span class="line">-- 通用写法: case 字段 when 值 then 新值1 else 新值2 end</span><br><span class="line">SELECT case gender WHEN 1 THEN '男' ELSE '女' END as '性别' FROM t_student;</span><br><span class="line"></span><br><span class="line">-- 4.4对列进行合并</span><br><span class="line">-- select concat(字段1,字段2,...) from 表名;</span><br><span class="line">SELECT CONCAT(stuname,stuid) as 'name_id' FROM t_student;</span><br><span class="line">SELECT CONCAT(stuname,':',stuid) as 'name_id' FROM t_student;</span><br><span class="line">-- 注意: 数字和字符串数据可以合并,bit类型的数据不可以合并</span><br><span class="line">-- SELECT CONCAT(stuname,':',gender) as 'name_id' FROM t_student; </span><br><span class="line"></span><br><span class="line">-- 4.5模糊查询 - 查询的时候时候通过like条件来指定查询对象</span><br><span class="line">-- sql中支持逻辑运算符and(逻辑与运算)和or(逻辑或运算),not(逻辑非)</span><br><span class="line">SELECT * FROM t_student WHERE stuname like '%飞%' or not stuid < 110; </span><br><span class="line"></span><br><span class="line">-- 4.6排序(先按之前的任何语法进行查询在排序)</span><br><span class="line">-- select * from 表名 order by 字段; - 对查询结果按照指定字段的值进行升序排序 </span><br><span class="line">-- select * from 表名 order by 字段 asc; - 对查询结果按照指定字段的值进行升序排序 </span><br><span class="line">-- select * from 表名 order by 字段 desc; - 对查询结果按照指定字段的值进行降序排序</span><br><span class="line">SELECT * FROM t_student ORDER BY gender; -- 按性别升序排序</span><br><span class="line">SELECT * FROM t_student ORDER BY stuid ASC; -- 按学号升序排序</span><br><span class="line">SELECT * FROM t_student ORDER BY stuid DESC; -- 按学号降序排序</span><br><span class="line"></span><br><span class="line">-- 排序的时候可以通过在order by的后边加多个字段,进行联排。排序的时候前面的字段的优先级高些</span><br><span class="line">SELECT * FROM t_student ORDER BY gender ASC, stuid DESC; -- 先按性别进行升序排序,然后再按学号降序排序。 </span><br><span class="line"></span><br><span class="line">-- 4.7限制 </span><br><span class="line">-- select * from 表名 limit N; -- 获取查询结果的前N条记录</span><br><span class="line">SELECT * FROM t_student LIMIT 3; -- 获取查询结果的前3条记录</span><br><span class="line"></span><br><span class="line">-- select * from 表名 limit M offset N; -- 对查询结果跳过前N条数据,取M条数据出来 </span><br><span class="line">SELECT * FROM t_student LIMIT 3 offset 4; -- 跳过前4数据,然后取3条数据</span><br><span class="line">-- =================================sql基础补充===============================</span><br><span class="line">-- 1.条件语句的写法</span><br><span class="line">-- 在SQL中可以通过 `where 条件语句`来对操作对象进行筛选 - 筛选 </span><br><span class="line">-- a. 比较运算符: =, <>, >, <, >=, <=</span><br><span class="line">-- 注意: 判断一个字段的值是否为空不用使用=和<>, 而是使用`is null` 和 `is not null`</span><br><span class="line">SELECT addr FROM t_student;</span><br><span class="line">SELECT stuname FROM t_student WHERE addr is NULL; -- 判断是否为NULL(空)</span><br><span class="line">SELECT stuname FROM t_student WHERE addr=''; -- 判断是否是空串</span><br><span class="line">-- b. 逻辑运算符: and, or, not </span><br><span class="line">-- c. where 字段名 between 值1 and 值2 -- 筛选指定的字段的值在值1和值2之间</span><br><span class="line">SELECT stuname,birth FROM t_student WHERE birth BETWEEN '1990-1-1' AND '1999-12-31'; </span><br><span class="line">-- d. where 字段名 in 集合 -- 筛选出字段值是集合中的元素;(集合是使用括号括起来里面多个值)</span><br><span class="line">SELECT * FROM t_student WHERE stuname in ('小花', '小明', '路飞'); </span><br><span class="line">-- e. like操作 </span><br><span class="line"></span><br><span class="line">-- 2.数据类型 </span><br><span class="line">-- varchar(size): 不定长字符串,size决定的是最大长度</span><br><span class="line">-- char(size): 定长字符 </span><br><span class="line">-- text: 不限长度(最大是255个字符)</span><br><span class="line">-- int/tinyint(-128~127)</span><br><span class="line">-- FLOAT(size,d)/DOUBLE(size,d) - 这儿的size和d的值都有约束效果</span><br><span class="line">-- bit: 只有0和1两个值</span><br><span class="line">-- date/datetime/time: 值可以是时间函数的结果,也可以时间字符串;计算或者是比较的时候内部是按时间处理的</span><br><span class="line">UPDATE t_student SET tel='1367819230';</span><br><span class="line">ALTER TABLE t_student ADD COLUMN intro VARCHAR(10);</span><br><span class="line">SELECT * FROM t_student; </span><br><span class="line"></span><br><span class="line">-- 3.去重 </span><br><span class="line">SELECT DISTINCT addr FROM t_student; </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- ========================添加约束=========================</span><br><span class="line">-- 1.创建表的时候添加约束</span><br><span class="line">CREATE TABLE if not EXISTS t_college</span><br><span class="line">(</span><br><span class="line">collid int, </span><br><span class="line">collname VARCHAR(20) NOT NULL, -- 创建表的时候添加约束</span><br><span class="line">website VARCHAR(1024), </span><br><span class="line">intro VARCHAR(200),</span><br><span class="line">PRIMARY KEY(collid)</span><br><span class="line">);</span><br><span class="line"></span><br><span class="line">-- 2.通过添加约束索引的方式添加约束 </span><br><span class="line">-- a.添加约束</span><br><span class="line">-- alter table 表名 add constraint 索引名 约束 (字段名);</span><br><span class="line">-- 说明: 索引名 - 自己随便命名,用来指向当前添加的约束; 约束 - 需要添加的约束(支持唯一约束、主键约束和外键约束)</span><br><span class="line"></span><br><span class="line">ALTER TABLE t_college ADD CONSTRAINT con_website UNIQUE (website); </span><br><span class="line">-- 给t_college表中的website添加unique约束,约束索引为con_website</span><br><span class="line"></span><br><span class="line">-- b.删除约束</span><br><span class="line">-- alter table 表名 drop index 约束索引;</span><br><span class="line">ALTER TABLE t_college DROP index con_website;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- ====================外键和E.R图================</span><br><span class="line">-- 1.什么是外键:表中的某个字段的值是根据其他表中主键的值来确定的。那么这个字段就是外键 </span><br><span class="line">-- 1.1 多对一的外键的添加: 将外键添加到多的一方对应的表中 </span><br><span class="line">-- 一对一的外键的添加: 将外键随便添加到哪一方,同时添加值唯一约束 </span><br><span class="line">-- 多对多的外键的添加: 关系型数据库中,两张表没法实现多多的关系,需要一个中间表。(中间表有两个外键分别参照多多的两个表的主键)</span><br><span class="line">-- 1.2 怎么添加外键: </span><br><span class="line"></span><br><span class="line">-- a.添加外键对应的字段 </span><br><span class="line">alter TABLE tb_student add COLUMN collid int;</span><br><span class="line"></span><br><span class="line">-- b.给设计好的外键对应的字段添加外键约束</span><br><span class="line">-- alter table 表1 add constraint 索引名 foreign key (字段1) references 表2 (字段2); </span><br><span class="line">-- - 将表1中的字段1设置为外键,并且让这个外键的值参照表2中的字段2</span><br><span class="line">ALTER TABLE tb_student ADD CONSTRAINT fk_collid_stu </span><br><span class="line">FOREIGN KEY (collid) </span><br><span class="line">REFERENCES tb_college (collid);</span><br><span class="line"></span><br><span class="line">-- c. 删除外键约束 </span><br><span class="line">-- alter table 表名 drop foreign key 外键索引名; - 可以删除外键约束,但是外键索引还存在;需要额外的把索引删掉</span><br><span class="line">-- 注意: 删除外键约束的时候直接删除约束的索引无效,必须先将约束删掉,然后再删除索引.</span><br><span class="line">ALTER TABLE tb_student DROP FOREIGN KEY fk_collid_stu;</span><br><span class="line">ALTER TABLE tb_student DROP INDEX fk_collid_stu; </span><br><span class="line"></span><br><span class="line">-- d. 多对多的外键约束</span><br><span class="line">-- 添加学生的外键约束 </span><br><span class="line">ALTER TABLE tb_score ADD CONSTRAINT fk_stuid_score </span><br><span class="line">FOREIGN KEY (stuid) </span><br><span class="line">REFERENCES tb_student (stuid);</span><br><span class="line"></span><br><span class="line">-- 添加课程的外键约束</span><br><span class="line">ALTER TABLE tb_score ADD CONSTRAINT fk_couid_score </span><br><span class="line">FOREIGN KEY (couid) </span><br><span class="line">REFERENCES tb_course (couid);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- ==================查询的高级操作================= </span><br><span class="line">-- 1.聚合:max()/min()/sum()/avg()/count()</span><br><span class="line">-- SELECT 聚合函数(字段) FROM 表名WHERE 条件; -- 按条件多表查询指定字段数据,然后将查询结果做相应的聚合运算。聚合运算的结果是最后结果 </span><br><span class="line">SELECT mark FROM tb_score; -- 获取tb_score表中的所有分数值</span><br><span class="line">SELECT max(mark) as maxmark FROM tb_score; -- 获取tb_score表中所有分数的最大值</span><br><span class="line">SELECT min(mark) FROM tb_score; </span><br><span class="line">SELECT sum(mark) FROM tb_score; </span><br><span class="line">SELECT avg(mark) FROM tb_score WHERE scoreid>=123; -- 计算平均值的时候如果参与运算的对象的值为NULL,那么这个数据不会参与计算</span><br><span class="line">SELECT count(mark) FROM tb_score WHERE mark>=90;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- 2.分组 </span><br><span class="line">-- SELECT 字段操作 FROM 表名 WHERE 条件 GROUP BY(字段2); </span><br><span class="line">-- 将指定表中满足条件的记录按照字段2的进行分组(值是一样的在一个组里面), 然后再讲每个分组作为整体按照指定字段进行指定聚合操作</span><br><span class="line">-- 求每个学生的平均成绩</span><br><span class="line">SELECT stuid,avg(mark) FROM tb_score WHERE scoreid <= 115 GROUP BY(stuid) ;</span><br><span class="line">-- 注意:a.字段操作的位置除了分组字段不用聚合,其他字段都必须聚合 b.分组的时候where要放到分组前对需要分组的数据进行筛选</span><br><span class="line"></span><br><span class="line">-- having: 分组的时候,在分组后用having代替where来对分组后的数据进行筛选</span><br><span class="line">-- 获取平均分数大于60分的学生的id</span><br><span class="line">SELECT stuid,avg(mark) FROM tb_score GROUP BY(stuid) HAVING avg(mark)>60;</span><br><span class="line"></span><br><span class="line">-- 3.子查询: 将一个查询操作的结果作为另外一个查询的数据源</span><br><span class="line">-- 在tb_score表中获取成绩是大于90分的学生的id</span><br><span class="line">SELECT stuid FROM tb_score WHERE mark>90 and stuid is not NULL; </span><br><span class="line"></span><br><span class="line">-- 获取成绩大于90分的学生的名字</span><br><span class="line">SELECT stuname FROM tb_student WHERE stuid in </span><br><span class="line">(SELECT stuid FROM tb_score WHERE mark>90 and stuid is not NULL); </span><br><span class="line"></span><br><span class="line"></span><br><span class="line">SELECT stuid,mark FROM tb_score WHERE mark > 90 and stuid is not NULL;</span><br><span class="line">-- 将一个查询的结果作为查询对象提供给另外一个查询。但是第一个查询结果需要重命名</span><br><span class="line">SELECT mark FROM (SELECT stuid,mark FROM tb_score WHERE mark > 90 and stuid is not NULL) as t2;</span><br><span class="line"></span><br><span class="line">-- ========================连接查询===============================</span><br><span class="line">-- 1.连接查询:同时查询多个表中的数据</span><br><span class="line">-- select * from 表名1,表名2... where 连接条件;</span><br><span class="line">-- 连接查询如果不加连接条件,结果是笛卡尔积:(a,b,c)(1,2,3)——>(a1,a2,a3,b1,b2,b3,c1,c2,c3)</span><br><span class="line"></span><br><span class="line">-- 获取老师姓名和其对应的学院名</span><br><span class="line">select teaname,collname from tb_college,tb_teaher where tb_college.collid=tb_student.collid;</span><br><span class="line"></span><br><span class="line">-- 获取学生姓名和其指定课程的分数</span><br><span class="line">select stuname,couname,mark from tb_student,tb_course,tb_score where tb_student.stuid=tb_score.stuid and tb_course.couid=tb_score.couid;</span><br><span class="line"></span><br><span class="line">-- 注意:如果连接查询的时候既有连接条件又有筛选条件,我们要把筛选条件写在连接条件后面</span><br><span class="line">-- 查询平均成绩大于80分的学生姓名对应的学生的平均成绩</span><br><span class="line">select stuname,avg_mark from tb_student,(select stuid,avg(mark) as avg_mark from tb_score group by(stuid)) as temp_t where tb_student.stuid = temp_t.stuid and avg_mark>80;</span><br><span class="line"></span><br><span class="line">-- 2.内连接</span><br><span class="line">-- select * from 表1 inner join 表2 on 表2的连接条件 inner join 表3 on 表3的连接条件 ...;</span><br><span class="line">-- 注意:中间表写在最前面(存在关联其他表外键的表)</span><br><span class="line">-- 查询学生姓名对应的学科名的分数</span><br><span class="line">select stuname,couname,mark from tb_score inner join tb_student on tb_student.stuid=tb_score.stuid inner join tb_course on tb_course.couid=tb_score.couid where mark<60;</span><br><span class="line">-- 内连接把满足条件的记录取出来</span><br><span class="line">-- 3.外连接</span><br><span class="line">-- 外连接分为左外连接、右外连接和全连接,但是在mysql中只支持左外连接和右外连接</span><br><span class="line">-- 表1(左表) left/right/inner jion 表2(右表)</span><br><span class="line">-- 左外连接:将左表中所有对应字段的所有数据取出,然后再查出对应的右表中对应字段的值,如果右表对应的值不存在结果为null</span><br><span class="line">-- 右外连接:将右表中所有对应字段的所有数据取出,然后再查出对应的左表中对应字段的值,如果左表对应的值不存在结果为null</span><br><span class="line">-- 查所有学生名对应的成绩</span><br><span class="line">select stuname,mark from tb_score inner join tb_student on tb_student.stuid=tb_score.stuid;</span><br><span class="line">select stuname,mark from tb_score left join tb_student on tb_student.stuid=tb_score.stuid;</span><br><span class="line"></span><br><span class="line">-- ========================字段索引==============================</span><br><span class="line">-- explain: 获取执行</span><br><span class="line"></span><br><span class="line">-- 字段的索引就相当于目录,作用是为了能够快速的对这个字段进行查找</span><br><span class="line">-- 添加索引的好处是可以大大的提高查询效率; 缺点:1.会消耗额外的存储空间 2.会让添加和删除的效率降低。</span><br><span class="line">-- 建议:1. 索引不能滥用 2.如果项目中针对某个字段的查询很频繁,建议加个对应的索引</span><br><span class="line">explain select * from tb_student where stuid=1;</span><br><span class="line">explain select * from tb_student where stuname='张三';</span><br><span class="line"></span><br><span class="line">-- 添加索引</span><br><span class="line">-- create index 索引名称 on 表名 (字段名); - 给指定表中的指定字段添加索引</span><br><span class="line">create index index_stuname on tb_student (stuname); -- 给名字加索引</span><br><span class="line">create index index_stuname1 on tb_student (stuname(1)); -- 按姓加索引</span><br><span class="line"></span><br><span class="line">-- 删除索引</span><br><span class="line">alter table tb_student drop index index_stuname;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">-- =========================DCL========================</span><br><span class="line">-- 1.创建用户</span><br><span class="line">-- create user 用户名@登录地址</span><br><span class="line">-- 登录地址: (限制用户能够登录mysql的主机地址),ip地址(指定地址),localhost(数据库本机),%(任何位置)</span><br><span class="line">create user 'zhangsan'@'%' identified by 'aaaaaa'; </span><br><span class="line">-- 删除用户: drop user 用户名;</span><br><span class="line">drop user 用户名;</span><br><span class="line"></span><br><span class="line">-- 2.授权</span><br><span class="line">-- grant 权限类型 on 数据库.对象 to 用户名;</span><br><span class="line">grant select on *.* to 'zhangshan';</span><br><span class="line">grant update on *.* to 'zhangshan';</span><br><span class="line">grant all privileges on *.* to 'zhangshan'; -- 添加所有权限</span><br><span class="line">grant all privileges on *.* to 'zhangshan' with grant option; -- 添加所有权限,并且能够将自己的权限再授权给其他用户</span><br><span class="line"></span><br><span class="line">-- 3.召回授权</span><br><span class="line">-- revoke 权限类型 on 数据库.对象 from 用户名;</span><br><span class="line">revoke delete on school.* from 'zhangshan';</span><br><span class="line"></span><br><span class="line">-- 4.事务</span><br><span class="line">-- 完成一个任务需要执行多条sql,但是要求这多个操作当中只要有一个操作失败,整个任务就失败,数据全部还原,所有的操作都成功整个任务才成功的时候就使用事务。</span><br><span class="line"></span><br><span class="line">-- 开启事务环境</span><br><span class="line">begin;</span><br><span class="line">update tb_student set stuname = '一一' where stuname='12';</span><br><span class="line">delete from tb_student where stuid=110;</span><br><span class="line"></span><br><span class="line">-- 提交事务(只有begin到commit之间的所有的sql都执行成功,才会执行commit;否则执行rollback)</span><br><span class="line">commit;</span><br><span class="line"></span><br><span class="line">-- 事务回滚(放弃begin到commit之间执行成功的所有sql语句的结果)</span><br><span class="line">rollback;</span><br><span class="line"></span><br><span class="line">-- 8.pyMySQL</span><br><span class="line">1.建立连接</span><br><span class="line"> host - 要连接的数据库所在的主机地址(远程连接用ip地址,本机使用'localhost')</span><br><span class="line"> user - 用户名</span><br><span class="line"> password - 密码</span><br><span class="line"> database - 数据库</span><br><span class="line"> port - 端口</span><br><span class="line"> charset - 编码方式</span><br><span class="line"> con_obj = pymysql.connect(host='47.101.0.09',</span><br><span class="line"> user='root',</span><br><span class="line"> password='aaaaa',</span><br><span class="line"> database='school',</span><br><span class="line"> port=3306,</span><br><span class="line"> charset='utf8',</span><br><span class="line"> autocommit=True</span><br><span class="line"> )</span><br><span class="line"> print(con_obj)</span><br><span class="line"></span><br><span class="line"> 2.获得游标对象 - 提供数据库操作的上下文</span><br><span class="line"> 注意:游标提供的上下文是事务环境</span><br><span class="line"> with con_obj.cursor() as cursor:</span><br><span class="line"> 在这后面操作数据库</span><br><span class="line"> 3.操作数据库,执行sql语句:连接对象.execute(sql语句)</span><br><span class="line"> 返回执行结果,如果是增删改操作,结果是否成功:1-成功,0-失败</span><br><span class="line"> result = cursor.execute("update tb_teacher set teaage=25;")</span><br><span class="line"> print(result)</span><br><span class="line"></span><br><span class="line"> 事务提交</span><br><span class="line"> con_obj.commit()</span><br><span class="line"></span><br><span class="line"> 关闭连接:连接对象.close()</span><br><span class="line"> con_obj.close()</span><br></pre></td></tr></table></figure>
</div>
<footer class="post-footer">
<div class="post-eof"></div>
</footer>
</div>
</article>
<article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
<div class="post-block">
<link itemprop="mainEntityOfPage" href="LittleMaoer.github.io/2019/02/25/Nginx服务器安装/">
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
<meta itemprop="name" content="高盛茂">
<meta itemprop="description" content="学习python编程的python小白">
<meta itemprop="image" content="http://pndcgm4gq.bkt.clouddn.com/%E5%A4%B4%E5%83%8F.jpg">
</span>
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
<meta itemprop="name" content="欢迎来到这里">
</span>
<header class="post-header">
<h1 class="post-title" itemprop="name headline">
<a href="/2019/02/25/Nginx服务器安装/" class="post-title-link" itemprop="url">Nginx服务器的安装配置</a>
</h1>
<div class="post-meta">
<span class="post-time">
<span class="post-meta-item-icon">
<i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">发表于</span>
<time title="创建时间:2019-02-25 20:26:51 / 修改时间:20:26:44" itemprop="dateCreated datePublished" datetime="2019-02-25T20:26:51+08:00">2019-02-25</time>
</span>