鐘舵�佷唬鐮佹湁涓変綅鏁板瓧缁勬垚锛岀涓�涓暟瀛楀畾涔変簡鍝嶅簲鐨勭被鍒紝涓旀湁浜旂鍙兘鍙栧�硷細
1xx锛氭寚绀轰俊鎭�撹〃绀鸿姹傚凡鎺ユ敹锛岀户缁鐞�
2xx锛氭垚鍔熲�撹〃绀鸿姹傚凡琚垚鍔熸帴鏀躲�佺悊瑙c�佹帴鍙�
3xx锛氶噸瀹氬悜鈥撹瀹屾垚璇锋眰蹇呴』杩涜鏇磋繘涓�姝ョ殑鎿嶄綔
4xx锛氬鎴风閿欒鈥撹姹傛湁璇硶閿欒鎴栬姹傛棤娉曞疄鐜�
5xx锛氭湇鍔″櫒绔敊璇�撴湇鍔″櫒鏈兘瀹炵幇鍚堟硶鐨勮姹�
甯歌鐘舵�佷唬鐮併�佺姸鎬佹弿杩般�佽鏄庯細
200 OK //瀹㈡埛绔姹傛垚鍔�
400 Bad Request //瀹㈡埛绔姹傛湁璇硶閿欒锛屼笉鑳借鏈嶅姟鍣ㄦ墍鐞嗚В
401 Unauthorized //璇锋眰鏈粡鎺堟潈锛岃繖涓姸鎬佷唬鐮佸繀椤诲拰 WWW-Authenticate 鎶ュご鍩熶竴璧蜂娇鐢�
403 Forbidden //鏈嶅姟鍣ㄦ敹鍒拌姹傦紝浣嗘槸鎷掔粷鎻愪緵鏈嶅姟
404 Not Found //璇锋眰璧勬簮涓嶅瓨鍦紝 eg锛氳緭鍏ヤ簡閿欒鐨� URL
500 Internal Server Error //鏈嶅姟鍣ㄥ彂鐢熶笉鍙鏈熺殑閿欒
503 Server Unavailable //鏈嶅姟鍣ㄥ綋鍓嶄笉鑳藉鐞嗗鎴风鐨勮姹傦紝涓�娈垫椂闂村悗鍙兘鎭㈠姝e父
1銆佷负浠�涔堝涔燩ython锛�
绠�鍗曟槗鎳傦紝璇█鏈韩绠�娲侊紝浼樼編,鍔熻兘瓒呯骇寮哄ぇ銆佽法骞冲彴銆侀潪甯哥伀鐖嗙殑绀惧尯銆�.寰堝鏈夊悕鐨勫ぇ鍏徃鍦ㄧ敤锛岃繎骞存潵鐨刾ython鐢ㄩ�旇秺鏉ヨ秺澶э紝鍦ㄧ紪绋嬭瑷�鐨勬帓鍚嶄腑绋虫鎻愬崌锛屾垜鐩镐俊锛宲ython蹇呬細鎴愪负鏈�鐑棬鐨勭紪绋嬭瑷�涔嬩竴
2銆侀�氳繃浠�涔堥�斿緞瀛︿範鐨凱ython锛�
閫氳繃姝h鐨勫煿璁満鏋勫涔犱互鍙婅嚜宸变拱涔﹁嚜瀛︺�佸湪缃戜笂鏌ユ壘璧勬枡銆佽棰�
3銆丳ython鍜孞ava銆丳HP銆丆銆丆#銆丆++绛夊叾浠栬瑷�鐨勫姣旓紵
鈶翠綔涓哄垵瀛ython鐨勭鐝嚭韬殑灏忕櫧锛宲ython闈炲父绠�鍗曪紝闈炲父閫傚悎浜虹被闃呰
鈶垫槗瀛︺�俻ython铏界劧鏄敤c璇█鍐欑殑锛屼絾鏄畠鎽堝純浜哻涓潪甯稿鏉傜殑鎸囬拡锛岀畝鍖栦簡python鐨勮娉曘��
鈶禤ython鏄疐LOSS锛堣嚜鐢�/寮�鏀炬簮鐮佽蒋浠讹級涔嬩竴銆�
鈶峰彲绉绘鎬р�斺�斺�斺�旂敱浜庡畠鐨勫紑婧愭湰璐紝Python宸茬粡琚Щ妞嶅湪璁稿骞冲彴涓�
鈶稿湪璁$畻鏈哄唴閮紝Python瑙i噴鍣ㄦ妸婧愪唬鐮佽浆鎹㈡垚绉颁负瀛楄妭鐮佺殑涓棿褰㈠紡锛岀劧鍚庡啀鎶婂畠缈昏瘧鎴愯绠楁満浣跨敤鐨勬満鍣ㄨ瑷�骞惰繍琛屻��
鈶筆ython鏃㈡敮鎸侀潰鍚戣繃绋嬬殑鍑芥暟缂栫▼涔熸敮鎸侀潰鍚戝璞$殑鎶借薄缂栫▼銆�
鈶� 鍙墿灞曟�у拰鍙祵鍏ユ�с��
鈶讳赴瀵岀殑搴撱��
聽鈶� Python纭疄鏄竴绉嶅崄鍒嗙簿褰╁張寮哄ぇ鐨勮瑷�銆�
(10)涔﹀啓瑙勮寖
4銆佺畝杩拌В閲婂瀷鍜岀紪璇戝瀷缂栫▼璇█锛�
缂栬瘧鍨嬭瑷�锛�
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽缂栬瘧鎬х殑璇█鎸囦娇鐢ㄤ笓闂ㄧ殑缂栬瘧鍣ㄣ�侀拡瀵圭壒瀹氬钩鍙帮紙鎿嶄綔绯荤粺锛夊皢鏌愮楂樼骇璇█婧愪唬鐮佷竴娆℃�р�滅炕璇戔�濇垚璇ュ钩鍙扮‖浠舵墽琛岀殑鏈哄櫒鐮�
瑙i噴鍨嬭瑷�锛�
聽 聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽瑙i噴鍨嬭瑷�鏄寚浣跨敤涓撻棬鐨勮В閲婂櫒瀵规簮绋嬪簭杩涜閫愯瑙i噴鎴愮壒瀹氬钩鍙扮殑鏈哄櫒鐮佸苟绔嬪嵆鎵ц鐨勮瑷�銆�
5銆丳ython瑙i噴鍣ㄧ绫讳互鍙婄壒鐐癸紵
CPython
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽褰撲粠Python瀹樻柟缃戠珯涓嬭浇骞跺畨瑁呭ソPython2.7鍚庯紝灏辩洿鎺ヨ幏寰椾簡涓�涓畼鏂圭増鏈殑瑙i噴鍣細Cpython锛岃繖涓В閲婂櫒鏄敤C璇█寮�鍙戠殑锛屾墍浠ュ彨CPython锛屽湪鍛藉悕琛屼笅杩愯python锛屽氨鏄惎鍔–Python瑙i噴鍣紝CPython鏄娇鐢ㄦ渶骞跨殑Python瑙i噴鍣ㄣ��
IPython
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽IPython鏄熀浜嶤Python涔嬩笂鐨勪竴涓氦浜掑紡瑙i噴鍣紝涔熷氨鏄锛孖Python鍙槸鍦ㄤ氦浜掓柟寮忎笂鏈夋墍澧炲己锛屼絾鏄墽琛孭ython浠g爜鐨勫姛鑳藉拰CPython鏄畬鍏ㄤ竴鏍风殑锛屽ソ姣斿緢澶氬浗浜ф祻瑙堝櫒铏界劧澶栬涓嶅悓锛屼絾鍐呮牳鍏跺疄鏄皟鐢ㄤ簡IE銆�
PyPy
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽PyPy鏄彟涓�涓狿ython瑙i噴鍣紝瀹冪殑鐩爣鏄墽琛岄�熷害锛孭yPy閲囩敤JIT鎶�鏈紝瀵筆ython浠g爜杩涜鍔ㄦ�佺紪璇戯紝鎵�浠ュ彲浠ユ樉钁楁彁楂楶ython浠g爜鐨勬墽琛岄�熷害銆�
Jython
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Jython鏄繍琛屽湪Java骞冲彴涓婄殑Python瑙i噴鍣紝鍙互鐩存帴鎶奝ython浠g爜缂栬瘧鎴怞ava瀛楄妭鐮佹墽琛屻��
IronPython
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽IronPython鍜孞ython绫讳技锛屽彧涓嶈繃IronPython鏄繍琛屽湪寰蒋.Net骞冲彴涓婄殑Python瑙i噴鍣紝鍙互鐩存帴鎶奝ython浠g爜缂栬瘧鎴�.Net鐨勫瓧鑺傜爜銆�
6銆佷綅鍜屽瓧鑺傜殑鍏崇郴锛�
1Byte=8bit
7銆乥銆丅銆並B銆丮B銆丟B 鐨勫叧绯伙紵
1GB=1024MB=1024虏KB=1024鲁B=8*1024鲁b
1MB=1024KB=1024虏B=8*1024虏b
1KB=1024B=8*1024b
1B=8b
8銆佽鑷冲皯鍒椾妇5涓� PEP8 瑙勮寖锛堣秺澶氳秺濂斤級銆�
聽聽聽聽聽聽聽聽1銆佺缉杩涖��4涓┖鏍肩殑缂╄繘锛堢紪杈戝櫒閮藉彲浠ュ畬鎴愭鍔熻兘锛夛紝涓嶄娇鐢═ap锛屾洿涓嶈兘娣峰悎浣跨敤Tap鍜岀┖鏍笺��
聽聽聽聽聽聽聽聽2銆佹瘡琛屾渶澶ч暱搴�79锛屾崲琛屽彲浠ヤ娇鐢ㄥ弽鏂滄潬锛屾渶濂戒娇鐢ㄥ渾鎷彿銆傛崲琛岀偣瑕佸湪鎿嶄綔绗︾殑鍚庤竟鏁插洖杞︺��
聽聽聽聽聽聽聽聽3銆佷笉瑕佸湪涓�鍙mport涓涓簱锛屾瘮濡俰mport os, sys涓嶆帹鑽�
聽聽聽聽聽聽聽聽4銆侀�楀彿銆佸啋鍙枫�佸垎鍙峰墠涓嶈鍔犵┖鏍笺�傚悗闈㈠姞绌烘牸
聽聽聽聽聽聽聽聽5銆佹�讳綋鍘熷垯锛岄伩鍏嶄笉蹇呰鐨勭┖鏍�
聽聽聽聽聽聽聽聽6銆佺被鐨勬柟娉曠涓�涓弬鏁板繀椤绘槸self锛岃�岄潤鎬佹柟娉曠涓�涓弬鏁板繀椤绘槸cls
9銆侀�氳繃浠g爜瀹炵幇濡備笅杞崲锛�
聽聽聽聽浜岃繘鍒惰浆鎹㈡垚鍗佽繘鍒讹細v = 鈥�0b1111011鈥�
聽聽聽聽print(int("0b1111011",2))
聽聽聽聽鍗佽繘鍒惰浆鎹㈡垚浜岃繘鍒讹細v = 18
聽聽聽聽print("杞崲涓轰簩杩涘埗涓猴細", bin(18))
聽聽聽聽鍏繘鍒惰浆鎹㈡垚鍗佽繘鍒讹細v = 鈥�011鈥�
聽聽聽聽print(int("011",8))
聽聽聽聽鍗佽繘鍒惰浆鎹㈡垚鍏繘鍒讹細v = 30
聽聽聽聽print("杞崲涓哄叓杩涘埗涓猴細", oct(30))
鍗佸叚杩涘埗杞崲鎴愬崄杩涘埗锛歷 = 鈥�0x12鈥�
print(int("0x12",16))
鍗佽繘鍒惰浆鎹㈡垚鍗佸叚杩涘埗锛歷 = 87
print("杞崲涓哄崄鍏繘鍒朵负锛�", hex(87))
10銆佽缂栧啓涓�涓嚱鏁板疄鐜板皢IP鍦板潃杞崲鎴愪竴涓暣鏁般��
import socket
import struct
def聽 聽ip2long(ip):
聽聽聽聽聽聽聽聽packedIP = socket.inet_aton(ip)
聽聽聽聽聽聽聽聽return struct.unpack("!L", packedIP)[0]
11銆乸ython閫掑綊鐨勬渶澶у眰鏁帮紵
榛樿鏈�澶ф鏁�1000锛岃繖鏄痯ython涓撻棬璁剧疆鐨勪竴绉嶆満鍒剁敤鏉ラ槻姝㈡棤闄愰�掑綊閫犳垚Python婧㈠嚭宕╂簝锛� 鏈�澶ч�掑綊娆℃暟鏄彲浠ラ噸鏂拌皟鏁寸殑
import sys
sys.setrecursionlimit(1500)# set the maximum depth as 1500
12銆佹眰缁撴灉锛�
v1 = 1 or 3
1
v2 = 1 and 3
3
v3 = 0 and 2 and 1
0
v4 = 0 and 2 or 1
1
v5 = 0 and 2 or 1 or 4
1
v6 = 0 or Flase and 1
False
13銆乤scii銆乽nicode銆乽tf-8銆乬bk 鍖哄埆锛�
ASCII鐮佷娇鐢ㄤ竴涓瓧鑺傜紪鐮侊紝鎵�浠ュ畠鐨勮寖鍥村熀鏈槸鍙湁鑻辨枃瀛楁瘝銆佹暟瀛楀拰涓�浜涚壒娈婄鍙� 锛屽彧鏈�256涓瓧绗︺��
Unicode鑳藉琛ㄧず鍏ㄤ笘鐣屾墍鏈夌殑瀛楄妭
UTF-8锛�8-bit Unicode Transformation Format锛夋槸涓�绉嶉拡瀵筓nicode鐨勫彲鍙橀暱搴﹀瓧绗︾紪鐮侊紝鍙堢О涓囧浗鐮�
GBK鏄彧鐢ㄦ潵缂栫爜姹夊瓧鐨勶紝GBK鍏ㄧО銆婃眽瀛楀唴鐮佹墿灞曡鑼冦�嬶紝浣跨敤鍙屽瓧鑺傜紪鐮併��
14銆佸瓧鑺傜爜鍜屾満鍣ㄧ爜鐨勫尯鍒紵
瀛楄妭鐮�
瀛楄妭鐮侀�氬父鎸囩殑鏄凡缁忕粡杩囩紪璇戯紝浣嗕笌鐗瑰畾鏈哄櫒鐮佹棤鍏筹紝闇�瑕佺洿璇戝櫒杞瘧鍚庢墠鑳芥垚涓烘満鍣ㄧ爜鐨勪腑闂翠唬鐮併��
瀛楄妭鐮侀�氬父涓嶅儚婧愮爜涓�鏍峰彲浠ヨ浜洪槄璇伙紝鑰屾槸缂栫爜鍚庣殑鏁板�煎父閲忋�佸紩鐢ㄣ�佹寚浠ょ瓑鏋勬垚鐨勫簭鍒椼��
瀛楄妭鐮佷富瑕佷负浜嗗疄鐜扮壒瀹氳蒋浠惰繍琛� 鍜岃蒋浠剁幆澧冦�佺‖浠剁幆澧冩棤鍏�
鎬荤粨锛氬瓧鑺傜爜鏄竴绉嶄腑闂寸姸鎬侊紙涓棿鐮侊級鐨勪簩杩涘埗浠g爜锛堟枃浠讹級銆傞渶瑕佺洿璇戝櫒杞瘧鍚庢墠鑳芥垚涓烘満鍣ㄧ爜銆�
鏈哄櫒鐮�
鏈哄櫒鐮佸氨鏄绠楁満鍙互鐩存帴鎵ц锛屽苟涓旀墽琛岄�熷害鏈�蹇殑浠g爜銆�
鐢ㄦ満鍣ㄨ瑷�缂栧啓绋嬪簭锛岀紪绋嬩汉鍛樿棣栧厛鐔熻鎵�鐢ㄨ绠楁満鐨勫叏閮ㄦ寚浠や唬鐮佸拰浠g爜鐨勬兜涔�
15銆佷笁鍏冭繍绠楄鍒欎互鍙婂簲鐢ㄥ満鏅紵
涓夊厓杩愮畻绗﹀氨鏄湪璧嬪�煎彉閲忕殑鏃跺�欙紝鍙互鐩存帴鍔犲垽鏂紝鐒跺悗璧嬪��
涓夊厓杩愮畻绗︾殑鍔熻兘涓�'if....else'娴佺▼璇彞涓�鑷达紝瀹冨湪涓�琛屼腑涔﹀啓锛屼唬鐮侀潪甯哥簿鐐硷紝鎵ц鏁堢巼鏇撮珮
鏍煎紡锛歔on_true] if [expression] else [on_false]
res = 鍊�1 if 鏉′欢 else 鍊�2
16銆佸垪涓� Python2鍜孭ython3鐨勫尯鍒紵
聽 聽 1銆乸rint
鍦╬ython2涓紝print琚涓轰竴涓鍙ヨ�屼笉鏄竴涓嚱鏁帮紝python3涓紝print()琚涓轰竴涓嚱鏁�
聽 聽 2銆佹暣鏁扮殑闄ゆ硶
鍦╬ython2涓紝閿叆鐨勪换浣曚笉甯﹀皬鏁扮殑鏁板瓧锛屽皢琚涓烘暣鏁扮殑缂栫▼绫诲瀷銆傛瘮濡�5/2=2锛岃В鍐虫柟娉曪細5.0/2.0=2.5
鍦╬ython3涓紝鏁存暟闄ゆ硶鍙樺緱鏇寸洿瑙� 5/2=2.5
聽 聽 3銆� Unicode
Python 2 榛樿浣跨敤 ASCII 瀛楁瘝琛�
Python 3 榛樿浣跨敤 Unicode
聽 聽 4銆佸悗缁彂灞�
Python 2.7 灏嗗湪 2020 骞村け鍘诲悗缁殑鏀寔锛�
Python 3 灏嗙户缁紑鍙戞洿澶氱殑鍔熻兘鍜屼慨澶嶆洿澶氱殑閿欒銆�
17銆佺敤涓�琛屼唬鐮佸疄鐜版暟鍊间氦鎹細
a = 1
b = 2
a,b = b,a
18銆丳ython3鍜孭ython2涓� int 鍜� long鐨勫尯鍒紵
int(绗﹀彿鏁存暟):閫氬父琚О涓烘槸鏁存暟鎴栨暣鏁�,娌℃湁灏忔暟鐐圭殑姝f垨璐熸暣鏁�
long(闀挎暣鏁�):鏃犻檺澶у皬鐨勬暣鏁�,杩欐牱鍐欐暣鏁板拰涓�涓ぇ鍐欐垨灏忓啓鐨凩
19銆亁range鍜宺ange鐨勫尯鍒紵
range
鍑芥暟璇存槑锛歳ange([start,] stop[, step])锛屾牴鎹畇tart涓巗top鎸囧畾鐨勮寖鍥翠互鍙妔tep璁惧畾鐨勬闀匡紝鐢熸垚涓�涓垪琛ㄣ��
xrange
鍑芥暟璇存槑锛歺range 鐢ㄦ硶涓� range 瀹屽叏鐩稿悓锛屾墍涓嶅悓鐨勬槸鐢熸垚鐨勪笉鏄竴涓猯ist瀵硅薄锛岃�屾槸涓�涓敓鎴愬櫒銆�
銆� 1.range鍜寈range閮芥槸鍦ㄥ惊鐜腑浣跨敤锛岃緭鍑虹粨鏋滀竴鏍枫��
聽 2.range杩斿洖鐨勬槸涓�涓猯ist瀵硅薄锛岃�寈range杩斿洖鐨勬槸涓�涓敓鎴愬櫒瀵硅薄(xrange object)銆�
銆� 3.xrange鍒欎笉浼氱洿鎺ョ敓鎴愪竴涓猯ist锛岃�屾槸姣忔璋冪敤杩斿洖鍏朵腑鐨勪竴涓�硷紝鍐呭瓨绌洪棿浣跨敤鏋佸皯锛屽洜鑰屾�ц兘闈炲父濂姐��
娉ㄦ剰锛歅ython 3.x宸茬粡鍘绘帀xrange锛屽叏閮ㄧ敤range浠f浛銆�
20銆佹枃浠舵搷浣滄椂锛歺readlines鍜宺eadlines鐨勫尯鍒紵
浜岃�呬娇鐢ㄦ椂鐩稿悓锛屼絾杩斿洖绫诲瀷涓嶅悓锛寈readlines杩斿洖鐨勬槸涓�涓敓鎴愬櫒锛宺eadlines杩斿洖鐨勬槸list
21銆佸垪涓惧竷灏斿�间负False鐨勫父瑙佸�硷紵
0 , [ ] , " , ( ) , { }
22銆佸瓧绗︿覆銆佸垪琛ㄣ�佸厓缁勩�佸瓧鍏告瘡涓父鐢ㄧ殑5涓柟娉曪紵
瀛楃涓�
words = 鈥榯oday is a wonderfulday鈥�
print(words.strip(鈥榯oday鈥�))#濡傛灉strip鏂规硶鎸囧畾涓�涓�肩殑璇濓紝閭d箞浼氬幓鎺夎繖涓や釜鍊�
print(words.count(鈥榓鈥�))#缁熻瀛楃涓插嚭鐜扮殑娆℃暟
print(words.index(鈥榠s鈥�))#鎵句笅鏍�
print(words.index(鈥榸鈥�))#鎵句笅鏍囧鏋滃厓绱犱笉鎵句笉鍒扮殑璇濓紝浼氭姤閿�
print(words.find(鈥榸鈥�))#鎵句笅鏍囷紝濡傛灉鍏冪礌鎵句笉鍒扮殑璇濓紝杩斿洖-1
print(words.replace(鈥榙ay鈥�,鈥楧AY鈥�))#瀛楃涓叉浛鎹�
鍒楄〃
sample_list = [鈥榓鈥�,1,(鈥榓鈥�,鈥榖鈥�)]聽 #鍒涘缓鍒楄〃
sample_list = [鈥榓鈥�,鈥榖鈥�,0,1,3]聽 #聽 Python 鍒楄〃鎿嶄綔
value_start = sample_list[0]聽 #寰楀埌鍒楄〃涓殑鏌愪竴涓��
end_value = sample_list[-1]聽 #寰楀埌鍒楄〃涓殑鏌愪竴涓��
del sample_list[0]聽 #鍒犻櫎鍒楄〃鐨勭涓�涓��
sample_list[0:0] = [鈥榮ample value鈥榏聽 #鍦ㄥ垪琛ㄤ腑鎻掑叆涓�涓��
鍏冪
#鍏冪粍涔熸槸涓�涓猯ist锛屼粬鍜宭ist鐨勫尯鍒槸鍏冪粍鐨勫厓绱犳棤娉曚慨鏀�
tuple1 = (2,3,4,5,6,4,7)
print(type(tuple1))
print(tuple1[:7])
print(tuple1[:5:-1])
for i in range(6):
聽 聽 print(tuple1[i])
for i in tuple1:
聽 聽 print(i)
瀛楀吀
D.get(key, 0)聽 聽 聽 #鍚宒ict[key]锛屽浜嗕釜娌℃湁鍒欒繑鍥炵己鐪佸�硷紝0銆俒]娌℃湁鍒欐姏寮傚父
D.has_key(key)聽 聽 聽 #鏈夎閿繑鍥濼RUE锛屽惁鍒橣ALSE
D.keys()聽 聽 聽 聽 聽 聽 #杩斿洖瀛楀吀閿殑鍒楄〃
D.clear()聽 聽 聽 聽 聽 #娓呯┖瀛楀吀锛屽悓del dict
D.copy()聽 聽 聽 聽 聽 聽 #鎷疯礉瀛楀吀
23銆乴ambda琛ㄨ揪寮忔牸寮忎互鍙婂簲鐢ㄥ満鏅紵
lambda琛ㄨ揪寮忥紝閫氬父鏄湪闇�瑕佷竴涓嚱鏁帮紝浣嗘槸鍙堜笉鎯宠垂绁炲幓鍛藉悕涓�涓嚱鏁扮殑鍦哄悎涓嬩娇鐢紝涔熷氨鏄寚鍖垮悕鍑芥暟銆�
add = lambda x, y : x+y
print(add(1,2))聽 # 缁撴灉涓�3
搴旂敤鍦ㄥ嚱鏁板紡缂栫▼涓� 搴旂敤鍦ㄩ棴鍖呬腑
24銆乸ass鐨勪綔鐢紵
1銆佺┖璇彞 do nothing
2銆佷繚璇佹牸寮忓畬鏁达紝淇濊瘉璇箟瀹屾暣
3銆佸崰浣嶈鍙�
25銆�*arg鍜�**kwarg浣滅敤
銆� *args锛氬彲浠ョ悊瑙d负鍙湁涓�鍒楃殑琛ㄦ牸锛岄暱搴︿笉鍥哄畾銆�
銆� **kwargs锛氬彲浠ョ悊瑙d负瀛楀吀锛岄暱搴︿篃涓嶅浐瀹氥��
1銆佸嚱鏁拌皟鐢ㄩ噷鐨�*arg鍜�**kwarg锛�
锛�1锛�*arg锛氬厓缁勬垨鍒楄〃鈥滃嚭鐜扳��
**kwarg锛氬瓧鍏糕�滃嚭娌♀��
锛�2锛夊垎鍓插弬鏁�
2銆佸嚱鏁板畾涔夋椂浼犵殑*arg /**kwarg:
锛�1锛夋帴鏀跺弬鏁�
26銆乮s鍜�==鐨勫尯鍒�
is鏄姣斿湴鍧�(id),==鏄姣斿��
27銆佺畝杩癙ython鐨勬繁娴呮嫹璐濅互鍙婂簲鐢ㄥ満鏅紵
娴呮嫹璐濓細copy.copy 娣辨嫹璐濓細copy.deepcopy
娴呮嫹璐濇寚浠呬粎鎷疯礉鏁版嵁闆嗗悎鐨勭涓�灞傛暟鎹紝娣辨嫹璐濇寚鎷疯礉鏁版嵁闆嗗悎鐨勬墍鏈夊眰
娣辨祬鎷疯礉锛�
銆�銆�涓昏搴旂敤鍦ㄥ瓧绗︿覆锛屾暟瀛楃殑娣辨祬鎷疯礉
28銆丳ython鍨冨溇鍥炴敹鏈哄埗锛�
Python鐨凣C妯″潡涓昏杩愮敤浜嗏�滃紩鐢ㄨ鏁扳�濓紙reference counting锛夋潵璺熻釜鍜屽洖鏀跺瀮鍦俱�傚湪寮曠敤璁℃暟鐨勫熀纭�涓婏紝杩樺彲浠ラ��
杩団�滄爣璁�-娓呴櫎鈥濓紙mark and sweep锛夎В鍐冲鍣ㄥ璞″彲鑳戒骇鐢熺殑寰幆寮曠敤鐨勯棶棰樸�傞�氳繃鈥滃垎浠e洖鏀垛�濓紙generation collection锛変互绌洪棿鎹㈠彇鏃堕棿鏉ヨ繘涓�姝ユ彁楂樺瀮鍦惧洖鏀剁殑鏁堢巼銆�
29銆丳ython鐨勫彲鍙樼被鍨嬪拰涓嶅彲鍙樼被鍨嬶紵
Python鐨勬瘡涓璞¢兘鍒嗕负鍙彉鍜屼笉鍙彉
銆�銆�鍙彉锛氬垪琛ㄣ�佸瓧鍏� 銆�涓嶅彲鍙橈細鏁板瓧銆佸瓧绗︿覆銆佸厓缁�
30銆佹眰缁撴灉锛�
v = dict.fromkeys(['k1','k2'],[])
v[鈥榢1鈥橾.append(666)
print(v)
v[鈥榢1鈥橾 = 777
print(v)
{'k1': [666], 'k2': [666]}
31銆佹眰缁撴灉锛�
def聽 num():
聽 聽 return [lambda x:i*x for i in range(4)]
print([ m(2) for m in num()])
[6, 6, 6, 6]
32銆佸垪涓惧父瑙佺殑鍐呯疆鍑芥暟锛�
1銆乤bs()聽 聽 姝ゅ嚱鏁拌繑鍥炴暟瀛楃殑缁濆鍊笺��
2銆乤ll()聽 聽 姝ゅ嚱鏁扮敤浜庡垽鏂粰瀹氱殑鍙凯浠e弬鏁� iterable 涓殑鎵�鏈夊厓绱犳槸鍚﹂兘涓嶄负 0銆侀兘涓嶄负False 鎴栬�卛terable閮� 涓虹┖锛屽鏋滄槸杩斿洖 True,鍚﹀垯杩斿洖 False銆�
3銆乥in()聽 聽 杩斿洖涓�涓暣鏁� int 鎴栬�呴暱鏁存暟 long int 鐨勪簩杩涘埗琛ㄧず銆�
4銆乥ool()聽 聽 鍑芥暟鐢ㄤ簬灏嗙粰瀹氬弬鏁拌浆鎹负甯冨皵绫诲瀷锛屽鏋滄病鏈夊弬鏁帮紝杩斿洖 False銆�
5銆乨ict()聽 聽 鍑芥暟鐢ㄤ簬鍒涘缓涓�涓瓧鍏搞��
33銆乫ilter銆乵ap銆乺educe鐨勪綔鐢紵
閫氫織鐨勮..閮芥槸鐢ㄥ湪涓�鍫嗘暟鎹�(姣斿涓�涓垪琛�)涓�..
map鏄敤鍚屾牱鏂规硶鎶婃墍鏈夋暟鎹兘鏀规垚鍒殑..瀛楅潰鎰忔�濇槸鏄犲皠..姣斿鎶婂垪琛ㄧ殑姣忎釜鏁伴兘鎹㈡垚鍏跺钩鏂�..
reduce鏄敤鏌愮鏂规硶渚濇鎶婃墍鏈夋暟鎹涪杩涘幓鏈�鍚庡緱鍒颁竴涓粨鏋�..瀛楅潰鎰忔�濇槸鍖栫畝..姣斿璁$畻涓�涓垪琛ㄦ墍鏈夋暟鐨勫拰鐨勮繃绋�,灏辨槸缁存寔涓�涓儴鍒嗗拰鐒跺悗渚濇鎶婃瘡涓暟鍔犺繘鍘�..
filter鏄瓫閫夊嚭鍏朵腑婊¤冻鏌愪釜鏉′欢鐨勯偅浜涙暟鎹�..瀛楅潰鎰忔�濇槸杩囨护..姣斿鎸戝嚭鍒楄〃涓墍鏈夊鏁�..
34銆佷竴琛屼唬鐮佸疄鐜�9*9涔樻硶琛�
print (鈥榎n鈥�.join([鈥� 鈥�.join([鈥�%s*%s=%-2s鈥� % (y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))
35銆佸浣曞畨瑁呯涓夋柟妯″潡锛熶互鍙婄敤杩囧摢浜涚涓夋柟妯″潡锛�
36銆佽嚦灏戝垪涓�8涓父鐢ㄦā鍧楅兘鏈夐偅浜�
pip銆乸ygame銆乸yMysql銆乻ys銆乵ath銆乼ime銆乷s
37銆乺e鐨刴atch鍜宻earch鍖哄埆锛�
re.match()浠庡紑澶村紑濮嬪尮閰峴tring銆�
re.search()浠巃nywhere 鏉ュ尮閰峴tring銆�
38銆佷粈涔堟槸姝e垯鐨勮椽濠尮閰嶏紵
璐┆鍖归厤:姝e垯琛ㄨ揪寮忎竴鑸秼鍚戜簬鏈�澶ч暱搴﹀尮閰嶏紝涔熷氨鏄墍璋撶殑璐┆鍖归厤
闈炶椽濠尮閰嶏細灏辨槸鍖归厤鍒扮粨鏋滃氨濂斤紝灏卞皯鐨勫尮閰嶅瓧绗�
榛樿鏄椽濠ā寮忥紱鍦ㄩ噺璇嶅悗闈㈢洿鎺ュ姞涓婁竴涓棶鍙凤紵灏辨槸闈炶椽濠ā寮忋��
39銆佹眰缁撴灉锛� a. [ i % 2 for i in range(10) ] b. ( i % 2 for i in range(10) )
40銆佹眰缁撴灉锛� a. 1 or 2 b. 1 and 2 c. 1 < (2==2) d. 1 < 2 == 2
41銆乨ef func(a,b=[]) 杩欑鍐欐硶鏈変粈涔堝潙锛�
42銆佸浣曞疄鐜� 鈥�1,2,3鈥� 鍙樻垚 [鈥�1鈥�,鈥�2鈥�,鈥�3鈥橾 ?
43銆佸浣曞疄鐜癧鈥�1鈥�,鈥�2鈥�,鈥�3鈥橾鍙樻垚[1,2,3] ?
44銆佹瘮杈冿細 a = [1,2,3] 鍜� b = [(1),(2),(3) ] 浠ュ強 b = [(1,),(2,),(3,) ] 鐨勫尯鍒紵
45銆佸浣曠敤涓�琛屼唬鐮佺敓鎴怺1,4,9,16,25,36,49,64,81,100] ?
46銆佷竴琛屼唬鐮佸疄鐜板垹闄ゅ垪琛ㄤ腑閲嶅鐨勫�� ?
47銆佸浣曞湪鍑芥暟涓缃竴涓叏灞�鍙橀噺 ?
48銆乴ogging妯″潡鐨勪綔鐢紵浠ュ強搴旂敤鍦烘櫙锛�
鍙互閫氳繃璁剧疆涓嶅悓鐨勬棩蹇楃瓑绾э紝鍦╮elease鐗堟湰涓彧杈撳嚭閲嶈淇℃伅锛岃�屼笉蹇呮樉绀哄ぇ閲忕殑璋冭瘯淇℃伅锛�
print灏嗘墍鏈変俊鎭兘杈撳嚭鍒版爣鍑嗚緭鍑轰腑锛屼弗閲嶅奖鍝嶅紑鍙戣�呬粠鏍囧噯杈撳嚭涓煡鐪嬪叾瀹冩暟鎹紱logging鍒欏彲浠ョ敱寮�鍙戣�呭喅瀹氬皢淇℃伅杈撳嚭鍒颁粈涔堝湴鏂癸紝浠ュ強鎬庝箞杈撳嚭锛�
49銆佽鐢ㄤ唬鐮佺畝绛斿疄鐜皊tack 銆�
50銆佸父鐢ㄥ瓧绗︿覆鏍煎紡鍖栧摢鍑犵锛�
51銆佺畝杩� 鐢熸垚鍣ㄣ�佽凯浠e櫒銆佸彲杩唬瀵硅薄 浠ュ強搴旂敤鍦烘櫙锛�
52銆佺敤Python瀹炵幇涓�涓簩鍒嗘煡鎵剧殑鍑芥暟銆�
53銆佽皥璋堜綘瀵归棴鍖呯殑鐞嗚В锛�
54銆乷s鍜宻ys妯″潡鐨勪綔鐢紵
OS妯″潡鏄疨ython鏍囧噯搴撲腑鐨勪竴涓敤浜庤闂搷浣滅郴缁熷姛鑳界殑妯″潡锛屼娇鐢∣S妯″潡涓彁渚涚殑鎺ュ彛锛屽彲浠ュ疄鐜拌法骞冲彴璁块棶
sys妯″潡涓昏鏄敤浜庢彁渚涘python瑙i噴鍣ㄧ浉鍏崇殑鎿嶄綔
55銆佸浣曠敓鎴愪竴涓殢鏈烘暟锛�
寮曞叆random妯″潡聽 random.random()
56銆佸浣曚娇鐢╬ython鍒犻櫎涓�涓枃浠讹紵
os.remove(path)
57銆佽皥璋堜綘瀵归潰鍚戝璞$殑鐞嗚В锛�
闈㈠悜瀵硅薄鏄悜鐜板疄涓栫晫妯″瀷鐨勮嚜鐒跺欢浼革紝杩欐槸涓�绉嶁�滀竾鐗╃殕瀵硅薄鈥濈殑缂栫▼鎬濇兂
鍦ㄧ幇瀹炵敓娲讳腑鐨勪换浣曠墿浣撻兘鍙互褰掍负涓�绫讳簨鐗╋紝鑰屾瘡涓�涓釜浣撻兘鏄竴绫讳簨鐗╃殑瀹炰緥
闈㈠悜瀵硅薄鐨勭紪绋嬫槸浠ュ璞′负涓績锛屼互娑堟伅涓洪┍鍔紝鎵�浠ョ▼搴�=瀵硅薄+娑堟伅
58銆丳ython闈㈠悜瀵硅薄涓殑缁ф壙鏈変粈涔堢壒鐐癸紵
缁ф壙鏄繘涓�姝ュ皢涓�绫讳簨鐗╁叡鏈夌殑灞炴�у拰琛屼负鎶借薄涓轰竴涓埗绫伙紝鑰屾瘡涓�涓瓙绫诲垯缁ф壙
浜嗙埗绫荤殑琛屼负鍜屽睘鎬э紝涔熸湁鑷繁鐗规湁鐨勮涓哄拰灞炴�с�傛墿灞曚唬鐮侊紝澧炲姞澶嶇敤鎬�
59銆侀潰鍚戝璞℃繁搴︿紭鍏堝拰骞垮害浼樺厛鏄粈涔堬紵
60銆侀潰鍚戝璞′腑super鐨勪綔鐢紵
61銆佹槸鍚︿娇鐢ㄨ繃functools涓殑鍑芥暟锛熷叾浣滅敤鏄粈涔堬紵
62銆佸垪涓鹃潰鍚戝璞′腑甯︾埥涓嬪垝绾跨殑鐗规畩鏂规硶锛屽锛歘_new__銆乢_init__
63銆佸浣曞垽鏂槸鍑芥暟杩樻槸鏂规硶锛�
鍑芥暟鏄皝瑁呬簡涓�浜涚嫭绔嬬殑鍔熻兘锛屽彲浠ョ洿鎺ヨ皟鐢紝python鍐呯疆浜嗚澶氬嚱鏁帮紝鍚屾椂鍙互鑷缓鍑芥暟鏉ヤ娇鐢�
鏂规硶鍜屽嚱鏁扮被浼硷紝鍚屾牱灏佽浜嗙嫭绔嬬殑鍔熻兘锛屼絾鏄柟娉曟槸闇�瑕侀�氳繃瀵硅薄鏉ヨ皟鐢ㄧ殑锛岃〃绀洪拡瀵硅繖涓璞¤鍋氱殑鎿嶄綔锛屼娇鐢ㄦ椂閲囩敤鐐规柟娉曘��
64銆侀潤鎬佹柟娉曞拰绫绘柟娉曞尯鍒紵
瀹炰緥鏂规硶锛岀被鏂规硶锛岄潤鎬佹柟娉曢兘鍙互閫氳繃瀹炰緥鎴栬�呯被璋冪敤锛屽彧涓嶈繃瀹炰緥鏂规硶閫氳繃绫昏皟鐢ㄦ椂闇�瑕佷紶閫掑疄渚嬬殑寮曠敤
涓夌鏂规硶浠庝笉鍚屽眰娆′笂鏉ュ鏂规硶杩涜浜嗘弿杩帮細瀹炰緥鏂规硶閽堝鐨勬槸瀹炰緥锛岀被鏂规硶閽堝鐨勬槸绫伙紝浠栦滑閮藉彲浠ョ户鎵垮拰閲嶆柊瀹氫箟锛岃�岄潤鎬佹柟娉曞垯涓嶈兘缁ф壙锛屽彲浠ヨ涓烘槸鍏ㄥ眬鍑芥暟銆�
65銆佸垪涓鹃潰鍚戝璞′腑鐨勭壒娈婃垚鍛樹互鍙婂簲鐢ㄥ満鏅�
榄旀湳鏂规硶 鐢ㄤ簬鍦ㄦ煇涓�鏃跺埢璋冪敤鏃�
66銆�1銆�2銆�3銆�4銆�5 鑳界粍鎴愬灏戜釜浜掍笉鐩稿悓涓旀棤閲嶅鐨勪笁浣嶆暟
for x in range(1,5):
聽 聽 for z in range(1,5):
if i != x and i != z and x != z:
聽 聽 print(i,x,z)
67銆佷粈涔堟槸鍙嶅皠锛熶互鍙婂簲鐢ㄥ満鏅紵
68銆乵etaclass浣滅敤锛熶互鍙婂簲鐢ㄥ満鏅紵
69銆佺敤灏介噺澶氱殑鏂规硶瀹炵幇鍗曚緥妯″紡銆�
70銆佽楗板櫒鐨勫啓娉曚互鍙婂簲鐢ㄥ満鏅��
71銆佸紓甯稿鐞嗗啓娉曚互鍙婂浣曚富鍔ㄨ窇鍑哄紓甯革紙搴旂敤鍦烘櫙锛�
try:
聽 聽 print("123")
expect:
聽 聽 print("456")
閫氳繃raise 寮傚父瀵硅薄涓诲姩鎶涘嚭寮傚父
72銆佷粈涔堟槸闈㈠悜瀵硅薄鐨刴ro
Method Realtion Order 鐢ㄦ潵鍒朵綔涓�涓户鎵垮叧绯荤殑鍒楄〃
MRO鍒楄〃鐨勫埗浣滃師鍒欙細
1銆佸瓙绫绘案杩滃湪鐖剁被鐨勫墠闈�
2銆佸鏋滅户鎵夸簡澶氫釜鐖剁被锛岄偅涔堟寜鐓�()涓殑椤哄簭鍦ㄥ垪琛ㄤ腑鎽嗘斁
3銆佸鏋滃涓被鍚屾椂缁ф壙浜嗕竴涓埗绫伙紝瀛欏瓙绫讳腑鍙細閫夊彇绗竴涓埗绫讳腑鐨勭埗绫荤殑璇ユ柟娉�
73銆乮sinstance浣滅敤浠ュ強搴旂敤鍦烘櫙锛�
妫�娴嬩竴涓暟鎹槸鍚︾敱鎸囧畾鐨勭被鍨嬪垱寤�
75銆乯son搴忓垪鍖栨椂锛屽彲浠ュ鐞嗙殑鏁版嵁绫诲瀷鏈夊摢浜涳紵濡備綍瀹氬埗鏀寔datetime绫诲瀷锛�
76銆乯son搴忓垪鍖栨椂锛岄粯璁ら亣鍒颁腑鏂囦細杞崲鎴恥nicode锛屽鏋滄兂瑕佷繚鐣欎腑鏂囨�庝箞鍔烇紵
json.dump(jsonDate,ensure_ascii=False)
77銆佷粈涔堟槸鏂█锛熷簲鐢ㄥ満鏅紵
鍦ㄦ病鏈変竴涓▼搴忎箣鍓嶏紝鎴戜滑涓嶇煡閬撶▼搴忎細鍦ㄥ摢閲屽嚭閿欙紝涓庡叾璁╁畠鍦ㄨ繍琛屼腑宕╂簝锛屼笉濡傚湪鍑虹幇閿欒鏉′欢鏃跺氨宕╂簝锛岃繖鏃跺�欏氨闇�瑕乤ssert鏂█鐨勫府鍔�
python assert鏂█鏄0鏄庡叾甯冨皵鍊煎繀椤讳负鐪熺殑鍒ゅ畾锛屽鏋滃彂鐢熷紓甯稿氨璇存槑琛ㄨ揪绀轰负鍋�
鍙互鐞嗚Вassert鏂█璇彞涓簉aise-if-not锛岀敤鏉ユ祴璇曡〃绀哄紡锛屽叾杩斿洖鍊间负鍋囷紝灏变細瑙﹀彂寮傚父銆�
78銆佹湁鐢ㄨ繃with statement鍚楋紵瀹冪殑濂藉鏄粈涔堬紵
with璇彞鐨勪綔鐢ㄦ槸閫氳繃鏌愮鏂瑰紡绠�鍖栧紓甯稿鐞�
鑷姩绠$悊鏂囦欢鍏抽棴
79銆佷娇鐢ㄤ唬鐮佸疄鐜版煡鐪嬪垪涓剧洰褰曚笅鐨勬墍鏈夋枃浠躲��
import os
80銆佺畝杩� yield鍜寉ield from鍏抽敭瀛椼��
yield 鐨勪綔鐢ㄥ氨鏄妸涓�涓嚱鏁板彉鎴愪竴涓敓鎴愬櫒锛屽甫鏈墆ield鐨勫嚱鏁颁笉鍐嶆槸涓�涓櫘閫氱殑鍑芥暟
yield from聽 generator 銆傚疄闄呬笂灏辨槸杩斿洖鍙﹀涓�涓敓鎴愬櫒
yield from 鍚庨潰鍙互璺熺殑寮忓瓙鏈夆�� 鐢熸垚鍣� 鍏冪粍 鍒楄〃绛夊彲杩唬瀵硅薄浠ュ強range锛堬級鍑芥暟浜х敓鐨勫簭鍒�
==================================绗簩閮ㄥ垎 缃戠粶缂栫▼鍜屽苟鍙戯紙34棰橈級===============================================
1銆佺畝杩� OSI 涓冨眰鍗忚銆�
鑷笅鑰屼笂渚濇涓�
鐗╃悊灞傘�佹暟鎹摼璺眰銆佺綉缁滃眰銆佷紶杈撳眰銆佷細璇濆眰銆佽〃绀哄眰銆佸簲鐢ㄥ眰
2銆佷粈涔堟槸C/S鍜孊/S鏋舵瀯锛�
B/S鏋舵瀯灏辨槸缁欎簣娴忚姹傜殑搴旂敤绋嬪簭锛岀綉绔欏氨鏄緢鍏稿瀷鐨勪唬琛紝鑰岄�氬父鎵�璇寸殑B/S鏋舵瀯鍒欐洿鏄寚鐨勬槸鍩轰簬缃戦〉鐨勭郴缁熴��
C/S浼犵粺绋嬪簭鏋舵瀯锛岃鏈夊鎴风鍜屾湇鍔″櫒绔紝鍏稿瀷鐨勪緥瀛怮Q灏辨槸鍩轰簬C/S鏋舵瀯鐨�,浣犳湰鍦板彧鏄竴涓鎴风锛岃�屼富绋嬪簭杩愯鍦ㄨ吘璁殑鏈嶅姟鍣ㄣ��
3銆佺畝杩� 涓夋鎻℃墜銆佸洓娆℃尌鎵嬬殑娴佺▼銆�
1銆佸缓绔嬭繛鎺ュ崗璁紙涓夋鎻℃墜锛�
锛�1锛夊鎴风鍙戦�佷竴涓甫SYN鏍囧織鐨凾CP鎶ユ枃鍒版湇鍔″櫒
锛�2锛� 鏈嶅姟鍣ㄧ鍥炲簲瀹㈡埛绔殑
锛�3锛� 瀹㈡埛蹇呴』鍐嶆鍥炲簲鏈嶅姟娈典竴涓狝CK鎶ユ枃
銆�2銆佽繛鎺ョ粓姝㈠崗璁紙鍥涙鎸ユ墜锛�
锛�1锛� TCP瀹㈡埛绔彂閫佷竴涓狥IN锛岀敤鏉ュ叧闂鎴峰埌鏈嶅姟鍣ㄧ殑鏁版嵁浼犻��
锛�2锛� 鏈嶅姟鍣ㄦ敹鍒拌繖涓狥IN锛屽畠鍙戝洖涓�涓狝CK锛岀‘璁ゅ簭鍙蜂负鏀跺埌鐨勫簭鍙峰姞1
锛�3锛� 鏈嶅姟鍣ㄥ叧闂鎴风鐨勮繛鎺ワ紝鍙戦�佷竴涓狥IN缁欏鎴风
锛�4锛� 瀹㈡埛娈靛彂鍥濧CK鎶ユ枃纭锛屽苟灏嗙‘璁ゅ簭鍙疯缃负鏀跺埌搴忓彿鍔�1
4銆佷粈涔堟槸arp鍗忚锛�
聽 聽 聽 ARP(Address Resolution Protocol)鍦板潃瑙f瀽鍗忚,鏄牴鎹甀P鍦板潃鑾峰彇鐗╃悊鍦板潃鐨勪竴涓猅CP/IP鍗忚
5銆乀CP鍜孶DP鐨勫尯鍒紵
1銆乀CP闈㈠悜杩炴帴锛堝鎵撶數璇濊鍏堟嫧鍙峰缓绔嬭繛鎺ワ級;UDP鏄棤杩炴帴鐨勶紝鍗冲彂閫佹暟鎹箣鍓嶄笉闇�瑕佸缓绔嬭繛鎺�
2銆乀CP鎻愪緵鍙潬鐨勬湇鍔°�傞�氳繃TCP杩炴帴浼犻�佺殑鏁版嵁锛屾棤宸敊锛屼笉涓㈠け锛屼笉閲嶅锛屼笖鎸夊簭鍒拌揪;UDP灏芥渶澶у姫鍔涗氦浠橈紝鍗充笉淇濊瘉鍙潬浜や粯
3銆乀CP闈㈠悜瀛楄妭娴侊紝瀹為檯涓婃槸TCP鎶婃暟鎹湅鎴愪竴杩炰覆鏃犵粨鏋勭殑瀛楄妭娴�
聽 UDP鏄潰鍚戞姤鏂囩殑锛孶DP娌℃湁鎷ュ鎺у埗锛屽洜姝ょ綉缁滃嚭鐜版嫢濉炰笉浼氫娇婧愪富鏈虹殑鍙戦�侀�熺巼闄嶄綆锛堝瀹炴椂搴旂敤寰堟湁鐢紝濡侷P鐢佃瘽锛屽疄鏃惰棰戜細璁瓑锛�
4銆佹瘡涓�鏉CP杩炴帴鍙兘鏄偣鍒扮偣鐨�;UDP鏀寔涓�瀵逛竴锛屼竴瀵瑰锛屽瀵逛竴鍜屽瀵瑰鐨勪氦浜掗�氫俊
5銆乀CP鐨勯�昏緫閫氫俊淇¢亾鏄叏鍙屽伐鐨勫彲闈犱俊閬擄紝UDP鍒欐槸涓嶅彲闈犱俊閬�
6銆佷粈涔堟槸灞�鍩熺綉鍜屽箍鍩熺綉锛�
灞�鍩熺綉鍜屽箍鍩熺綉鏄寜瑙勬ā澶у皬鑰屽垝鍒嗙殑涓ょ璁$畻鏈虹綉缁溿��
灞�鍩熺綉锛圠ocal Area Network锛夛紝绠�绉癓AN锛屾槸鎸囧湪鏌愪竴鍖哄煙鍐呯敱澶氬彴璁$畻鏈轰簰鑱旀垚鐨勮绠楁満缁勩��
鈥滄煇涓�鍖哄煙鈥濇寚鐨勬槸鍚屼竴鍔炲叕瀹ゃ�佸悓涓�寤虹瓚鐗┿�佸悓涓�鍏徃鍜屽悓涓�瀛︽牎绛夛紝涓�鑸槸鏂瑰渾鍑犲崈绫充互鍐呫��
骞垮煙缃戯紙Wide Area Network锛夛紝绠�绉癢AN锛屾槸涓�绉嶈法瓒婂ぇ鐨勩�佸湴鍩熸�х殑璁$畻鏈虹綉缁滅殑闆嗗悎
閫氬父璺ㄨ秺鐪併�佸競锛岀敋鑷充竴涓浗瀹躲�傚箍鍩熺綉鍖呮嫭澶уぇ灏忓皬涓嶅悓鐨勫瓙缃戯紝瀛愮綉鍙互鏄眬鍩熺綉锛屼篃鍙互鏄皬鍨嬬殑骞垮煙缃戙��
7銆佷负浣曞熀浜巘cp鍗忚鐨勯�氫俊姣斿熀浜巙dp鍗忚鐨勯�氫俊鏇村彲闈狅紵
tcp:TCP鐨勫彲闈犱繚璇�,鏄畠鐨勪笁娆℃彙鎵嬪弻鍚戞満鍒�,杩欎竴鏈哄埗淇濊瘉鏍¢獙浜嗘暟鎹�,淇濊瘉浜嗕粬鐨勫彲闈犳��
udp:涓嶅彲闈� 涓�鐩村彂鏁版嵁锛屼笉闇�瑕佸鏂瑰洖搴�
8銆佷粈涔堟槸socket锛熺畝杩板熀浜巘cp鍗忚鐨勫鎺ュ瓧閫氫俊娴佺▼銆�
Socket鏄簲鐢ㄥ眰涓嶵CP/IP鍗忚鏃忛�氫俊鐨勪腑闂磋蒋浠舵娊璞″眰锛屽畠鏄竴缁勬帴鍙c��
鏈嶅姟绔細鍒涘缓socket瀵硅薄锛岀粦瀹歩p绔彛bind(),聽 璁剧疆鏈�澶ч摼鎺ユ暟listen(),聽 accept()涓庡鎴风鐨刢onnect()鍒涘缓鍙屽悜绠¢亾锛� send(), recv(),close()
瀹㈡埛绔細鍒涘缓socket瀵硅薄锛宑onnect()涓庢湇鍔$accept()鍒涘缓鍙屽悜绠¢亾 ,聽 send(), recv(),close()
9銆佷粈涔堟槸绮樺寘锛� socket 涓�犳垚绮樺寘鐨勫師鍥犳槸浠�涔堬紵 鍝簺鎯呭喌浼氬彂鐢熺矘鍖呯幇璞★紵
绮樺寘锛氭暟鎹矘鍦ㄤ竴璧�
涓昏鍥犱负锛氭帴鏀舵柟涓嶇煡閬撴秷鎭箣闂寸殑鐣岄檺锛屼笉鐭ラ亾涓�娆℃�ф彁鍙栧灏戝瓧鑺傜殑鏁版嵁閫犳垚鐨�
鏁版嵁閲忔瘮杈冨皬锛屾椂闂撮棿闅旀瘮杈冪煭锛屽氨鍚堝苟鎴愪簡涓�涓寘锛岃繖鏄簳灞傜殑涓�涓紭鍖栫畻娉曪紙Nagle绠楁硶锛�
10銆両O澶氳矾澶嶇敤鐨勪綔鐢紵
I/O澶氳矾澶嶇敤鏄�氳繃涓�绉嶆満鍒讹紝鍙互鐩戣澶氫釜鎻忚堪绗︼紝涓�鏃︽煇涓弿杩扮灏辩华锛堜竴鑸槸璇诲氨缁垨鑰呭啓灏辩华锛夛紝鑳藉閫氱煡绋嬪簭杩涜鐩稿簲鐨勮鍐欐搷浣溿��
11銆佷粈涔堟槸闃茬伀澧欎互鍙婁綔鐢紵
绠�鍗曠殑鏉ヨ锛岄槻鐏灏辨槸涓�绉嶏紝閬垮厤浣犵殑鐢佃剳琚粦瀹㈠叆渚电殑涓�绉嶉槻鎶ゅ伐鍏凤紝涓�绉嶇‘淇濈綉缁滃畨鍏ㄧ殑鏂规硶锛�
璁剧疆闃茬伀澧欑洰鐨勯兘鏄负浜嗗湪鍐呴儴缃戜笌澶栭儴缃戜箣闂磋绔嬪敮涓�鐨勯�氶亾锛岀畝鍖栫綉缁滅殑瀹夊叏绠$悊銆�
1銆佸厑璁哥綉缁滅鐞嗗憳瀹氫箟涓�涓腑蹇冪偣鏉ラ槻姝㈤潪娉曠敤鎴疯繘鍏ュ唴閮ㄧ綉缁溿��
2銆佸彲浠ュ緢鏂逛究鍦扮洃瑙嗙綉缁滅殑瀹夊叏鎬э紝骞舵姤璀︺��
3锛庡彲浠ヤ綔涓洪儴缃睳AT锛堢綉缁滃湴鍧�鍙樻崲锛夌殑鍦扮偣锛屽埄鐢∟AT鎶�鏈紝灏嗘湁闄愮殑IP鍦板潃鍔ㄦ�佹垨闈欐�佸湴涓庡唴閮ㄧ殑IP鍦板潃瀵瑰簲璧锋潵锛岀敤鏉ョ紦瑙e湴鍧�绌洪棿鐭己鐨勯棶棰樸��
闃茬伀澧欏彲浠ラ樆姝㈤粦瀹㈠叆渚碉紝浣嗕笉鑳介槻姝㈢梾姣掑叆渚碉紒
12銆乻elect銆乸oll銆乪poll 妯″瀷鐨勫尯鍒紵
13銆佺畝杩� 杩涚▼銆佺嚎绋嬨�佸崗绋嬬殑鍖哄埆 浠ュ強搴旂敤鍦烘櫙锛�
杩涚▼鎷ユ湁鑷繁鐨勫爢鍜屾爤锛屾棦涓嶅叡浜爢涔熶笉鍏变韩鏍� 杩涚▼鐢辨搷浣滅郴缁熻皟搴�
绾跨▼鎷ユ湁鑷繁鐨勫爢鍜屽叡浜殑鏍� 鍏变韩鏍� 浣嗕笉鍏变韩鍫� 绾跨▼涔熸槸鐢辨搷浣滅郴缁熻皟搴�
鍗忕▼鍜岀嚎绋嬩竴鏍锋湁鑷繁鐨勫爢鍜屽叡浜殑鏍� 鍏变韩鏍堜絾涓嶅叡浜爢 鍗忕▼鐢卞紑鍙戜汉鍛樺湪閫傚綋鎯呭喌璋冪敤
14銆丟IL閿佹槸浠�涔堥锛�
GIL:Global Interpreter Lock 鍏ㄥ眬瑙i噴鍣ㄩ攣
褰撴垜浠敤澶氱嚎绋嬬殑鏃跺��,姣忎竴涓繘绋嬩腑鍙湁涓�涓狦IL閿�,閭d箞杩欏涓嚎绋嬩腑璋佹嬁鍒癎IL閿侊紝璋佸嵆鍙互鐢╟pu(ps:澶氫釜杩涚▼鏈夊涓狦il閿侊紝浣嗘瘡涓繘绋嬩腑鍙湁涓�涓狦IL)
15銆丳ython涓浣曚娇鐢ㄧ嚎绋嬫睜鍜岃繘绋嬫睜锛�
杩涚▼姹狅細浣跨敤multiprocessing.Pool
绾跨▼姹狅細浣跨敤ThreadPool妯″潡
16銆乼hreading.local鐨勪綔鐢紵
threadLocal瑙e喅浜嗗弬鏁板湪涓�涓嚎绋嬩腑鍚勪釜鍑芥暟涔嬮棿鐩镐簰浼犻�掔殑闂
涓�涓猼hreadLocal鍙橀噺铏界劧鏄叏灞�鍙橀噺锛屼絾姣忎釜绾跨▼閮藉彧鑳借鍐欒嚜宸辩嚎绋嬬殑鐙珛鍓湰 浜掍笉骞叉壈
17銆佽繘绋嬩箣闂村浣曡繘琛岄�氫俊锛�
鍒涘缓涓�涓猶ueue闃熷垪锛屾垨浣跨敤 from multiprocessing import Manage绠$悊瑕佽繘琛岄�氫俊鐨勬暟鎹�
18銆佷粈涔堟槸骞跺彂鍜屽苟琛岋紵
骞跺彂锛氭寚涓や釜鎴栧涓簨浠跺湪鍚屼竴鏃堕棿闂撮殧鍙戠敓
骞惰锛氭寚涓や釜鎴栧涓簨浠跺湪鍚屼竴鏃跺埢鍙戠敓
骞惰鏄湪涓嶅悓瀹炰綋涓婄殑澶氫釜浜嬩欢锛屽苟鍙戞槸鍦ㄥ悓涓�瀹炰綋涓婄殑澶氫釜浜嬩欢銆�
19銆佽繘绋嬮攣鍜岀嚎绋嬮攣鐨勪綔鐢紵
杩涚▼閿�:涔熸槸涓轰簡鎺у埗鍚屼竴鎿嶄綔绯荤粺涓涓繘绋嬭闂竴涓叡浜祫婧愶紝鍙槸鍥犱负绋嬪簭鐨勭嫭绔嬫�э紝鍚勪釜杩涚▼鏄棤娉曟帶鍒跺叾浠栬繘绋嬪璧勬簮鐨勮闂殑锛屼絾鏄彲浠ヤ娇鐢ㄦ湰鍦扮郴缁熺殑淇″彿閲忔帶鍒�
绾跨▼閿�:涓昏鐢ㄦ潵缁欐柟娉曘�佷唬鐮佸潡鍔犻攣銆傚綋鏌愪釜鏂规硶鎴栬�呬唬鐮佸潡浣跨敤閿佹椂锛岄偅涔堝湪鍚屼竴鏃跺埢鑷冲浠呮湁鏈変竴涓嚎绋嬪湪鎵ц璇ユ浠g爜
褰撴湁澶氫釜绾跨▼璁块棶鍚屼竴瀵硅薄鐨勫姞閿佹柟娉�/浠g爜鍧楁椂锛屽悓涓�鏃堕棿鍙湁涓�涓嚎绋嬪湪鎵ц锛屽叾浣欑嚎绋嬪繀椤昏绛夊緟褰撳墠绾跨▼鎵ц瀹屼箣鍚庢墠鑳芥墽琛岃浠g爜娈�
绾跨▼閿侊紝杩涚▼閿佺殑浣滅敤閮芥槸涓�鏍风殑锛屽彧鏄綔鐢ㄧ殑鑼冨洿澶у皬涓嶅悓銆�
杩涚▼閿佲�斺�斿ぇ浜庘�斺�旂嚎绋嬮攣锛岃兘鐢ㄧ嚎绋嬮攣鐨勬儏鍐典笅浣跨敤杩涚▼閿佷篃鏄彲浠ョ殑
20銆佽В閲婁粈涔堟槸寮傛闈為樆濉烇紵
寮傛鍙屾柟涓嶉渶瑕佸叡鍚岀殑鏃堕挓锛屼篃灏辨槸鎺ユ敹鏂逛笉鐭ラ亾鍙戦�佹柟浠�涔堟椂鍊欏彂閫侊紝鎵�浠ュ湪鍙戦�佺殑淇℃伅涓氨瑕佹湁鎻愮ず鎺ユ敹鏂瑰紑濮嬫帴鏀剁殑淇℃伅锛屽寮�濮嬩綅锛屽悓鏃跺湪缁撴潫鏃舵湁鍋滄浣嶃��
闈為樆濉炴ā寮忔槸鎸囧埄鐢╯ocket浜嬩欢鐨勬秷鎭満鍒讹紝Server绔笌Client绔箣闂寸殑閫氫俊澶勪簬寮傛鐘舵�併��
21銆佽矾鐢卞櫒鍜屼氦鎹㈡満鐨勫尯鍒紵
璺敱鍣�(Router)浜︾О閫夊緞鍣紝鏄湪缃戠粶灞傚疄鐜颁簰杩炵殑璁惧銆傚彲浠ヨ繛鎺ュ涓綉缁滄垨缃戞鐨勭綉缁滆澶囷紝鍖呮嫭灞�鍩熺綉鍜屽箍鍩熺綉銆�
浜ゆ崲鏈�(Switch)鏄竴绉嶅熀浜嶮AC(缃戝崱鐨勭‖浠跺湴鍧�)璇嗗埆锛屼负濮嬪彂鑰呭拰鎺ユ敹鑰呬箣闂村缓绔嬩复鏃剁殑鑱旂綉璺緞銆�
鍖哄埆锛�
1銆佸伐浣滃眰娆′笉鍚岋細浜ゆ崲鏈烘瘮璺敱鍣ㄦ洿绠�鍗曪紝璺敱鍣ㄦ瘮浜ゆ崲鍣ㄨ兘鑾峰彇鏇村淇℃伅
2銆佹暟鎹浆鍙戞墍渚濇嵁鐨勫璞′笉鍚�
3銆佷紶缁熺殑浜ゆ崲鏈哄彧鑳藉垎鍓插啿绐佸煙锛屼笉鑳藉垎鍓插箍鎾煙;鑰岃矾鐢卞櫒鍙互鍒嗗壊骞挎挱鍩�
4銆佽矾鐢卞櫒鎻愪緵浜嗛槻鐏鐨勬湇鍔�
22銆佷粈涔堟槸鍩熷悕瑙f瀽锛�
鍩熷悕瑙f瀽鏄妸鍩熷悕鎸囧悜缃戠珯绌洪棿IP锛岃浜轰滑閫氳繃娉ㄥ唽鐨勫煙鍚嶅彲浠ユ柟渚垮湴璁块棶鍒扮綉绔欑殑涓�绉嶆湇鍔�
23銆佸浣曚慨鏀规湰鍦癶osts鏂囦欢锛�
璁颁簨鏈墦寮�C:\Windows\System32\drivers\etc涓嬬殑hosts鏂囦欢杩涜淇敼
24銆佺敓浜ц�呮秷璐硅�呮ā鍨嬪簲鐢ㄥ満鏅強浼樺娍锛�
搴旂敤浜庝竴涓敓浜ф暟鎹竴涓鐞嗘暟鎹殑鍦烘櫙
浼樺娍鐢熶骇鑰呭拰娑堣垂鑰呬箣闂翠笉鐩存帴杩涜閫氫俊 鑰屾槸閫氳繃涓�涓槦鍒楃浉褰撲簬涓�涓紦鍐插尯锛屽钩琛′簡鐢熶骇鑰呭拰娑堣垂鑰呯殑澶勭悊鑳藉姏
25銆佷粈涔堟槸cdn锛�
CDN鐨勫叏绉版槸Content Delivery Network锛屽嵆鍐呭鍒嗗彂缃戠粶銆�
鍏剁洰鐨勬槸閫氳繃鍦ㄧ幇鏈夌殑Internet涓鍔犱竴灞傛柊鐨勭綉缁滄灦鏋勶紝灏嗙綉绔欑殑鍐呭鍙戝竷鍒版渶鎺ヨ繎鐢ㄦ埛鐨勭綉缁�"杈圭紭"锛屼娇鐢ㄦ埛鍙互灏辫繎鍙栧緱鎵�闇�鐨勫唴瀹癸紝瑙e喅 Internet缃戠粶鎷ユ尋鐨勭姸鍐碉紝鎻愰珮鐢ㄦ埛璁块棶缃戠珯鐨勫搷搴旈�熷害銆�
26銆丩VS鏄粈涔堝強浣滅敤锛�
27銆丯ginx鏄粈涔堝強浣滅敤锛�
Nginx鏄竴涓猦ttp鏈嶅姟鍣�
1銆� http鏈嶅姟鍣ㄣ�侼ginx鏄竴涓猦ttp鏈嶅姟鍙互鐙珛鎻愪緵http鏈嶅姟銆傚彲浠ュ仛缃戦〉闈欐�佹湇鍔″櫒銆�
2銆� 铏氭嫙涓绘満銆傚彲浠ュ疄鐜板湪涓�鍙版湇鍔″櫒铏氭嫙鍑哄涓綉绔欍�備緥濡備釜浜虹綉绔欎娇鐢ㄧ殑铏氭嫙涓绘満銆傚熀浜庣鍙g殑锛屼笉鍚岀殑绔彛鍩轰簬鍩熷悕鐨勶紝涓嶅悓鍩熷悕
3銆� 鍙嶅悜浠g悊锛岃礋杞藉潎琛°�傚綋缃戠珯鐨勮闂噺杈惧埌涓�瀹氱▼搴﹀悗锛屽崟鍙版湇鍔″櫒涓嶈兘婊¤冻鐢ㄦ埛鐨勮姹傛椂锛岄渶瑕佺敤澶氬彴鏈嶅姟鍣ㄩ泦缇ゅ彲浠ヤ娇鐢╪ginx鍋氬弽鍚戜唬鐞嗐��
骞朵笖澶氬彴鏈嶅姟鍣ㄥ彲浠ュ钩鍧囧垎鎷呰礋杞斤紝涓嶄細鍥犱负鏌愬彴鏈嶅姟鍣ㄨ礋杞介珮瀹曟満鑰屾煇鍙版湇鍔″櫒闂茬疆鐨勬儏鍐点��
28銆乲eepalived鏄粈涔堝強浣滅敤?
29銆乭aproxy鏄粈涔堜互鍙婁綔鐢紵
30銆佷粈涔堟槸璐熻浇鍧囪 锛�
璐熻浇鍧囪 鏄珮鍙敤缃戠粶鍩虹鏋舵瀯鐨勭殑涓�涓叧閿粍鎴愰儴鍒嗭紝鏈変簡璐熻浇鍧囪 锛屾垜浠�氬父鍙互灏嗘垜浠殑搴旂敤鏈嶅姟鍣ㄩ儴缃插鍙�
鐒跺悗閫氳繃璐熻浇鍧囪 灏嗙敤鎴风殑璇锋眰鍒嗗彂鍒颁笉鍚岀殑鏈嶅姟鍣ㄧ敤鏉ユ彁楂樼綉绔欍�佸簲鐢ㄣ�佹暟鎹簱鎴栧叾浠栨湇鍔$殑鎬ц兘浠ュ強鍙潬鎬с��
31銆佷粈涔堟槸rpc鍙婂簲鐢ㄥ満鏅紵
32銆佺畝杩� asynio妯″潡鐨勪綔鐢ㄥ拰搴旂敤鍦烘櫙銆�
asyncio鏄疨ython 3.4鐗堟湰寮曞叆鐨勬爣鍑嗗簱锛岀洿鎺ュ唴缃簡瀵瑰紓姝O鐨勬敮鎸併��
asyncio鐨勭紪绋嬫ā鍨嬪氨鏄竴涓秷鎭惊鐜�傛垜浠粠asyncio妯″潡涓洿鎺ヨ幏鍙栦竴涓狤ventLoop鐨勫紩鐢紝鐒跺悗鎶婇渶瑕佹墽琛岀殑鍗忕▼鎵斿埌EventLoop涓墽琛岋紝灏卞疄鐜颁簡寮傛IO銆�
33銆佺畝杩� gevent妯″潡鐨勪綔鐢ㄥ拰搴旂敤鍦烘櫙銆�
褰撲竴涓猤reenlet閬囧埌IO鎿嶄綔鏃讹紝姣斿璁块棶缃戠粶锛屽氨鑷姩鍒囨崲鍒板叾浠栫殑greenlet锛岀瓑鍒癐O鎿嶄綔瀹屾垚锛屽啀鍦ㄩ�傚綋鐨勬椂鍊欏垏鎹㈠洖鏉ョ户缁墽琛屻��
鐢变簬IO鎿嶄綔闈炲父鑰楁椂锛岀粡甯镐娇绋嬪簭澶勪簬绛夊緟鐘舵�侊紝鏈変簡gevent涓烘垜浠嚜鍔ㄥ垏鎹㈠崗绋嬶紝灏变繚璇佹�绘湁greenlet鍦ㄨ繍琛岋紝鑰屼笉鏄瓑寰匢O銆�
鐢变簬鍒囨崲鏄湪IO鎿嶄綔鏃惰嚜鍔ㄥ畬鎴愶紝鎵�浠event闇�瑕佷慨鏀筆ython鑷甫鐨勪竴浜涙爣鍑嗗簱锛岃繖涓�杩囩▼鍦ㄥ惎鍔ㄦ椂閫氳繃monkey patch瀹屾垚锛�
34銆乼wisted妗嗘灦鐨勪娇鐢ㄥ拰搴旂敤锛�
Twisted鏄敤Python瀹炵幇鐨勫熀浜庝簨浠堕┍鍔ㄧ殑缃戠粶寮曟搸妗嗘灦锛孴wisted鏀寔璁稿甯歌鐨勪紶杈撳強搴旂敤灞傚崗璁紝鍖呮嫭TCP銆乁DP銆丼SL/TLS銆丠TTP銆両MAP銆丼SH銆両RC浠ュ強FTP銆�
灏卞儚Python涓�鏍凤紝Twisted涔熷叿鏈夆�滃唴缃數姹犫�濓紙batteries-included锛夌殑鐗圭偣锛孴wisted瀵逛簬鍏舵敮鎸佺殑鎵�鏈夊崗璁兘甯︽湁瀹㈡埛绔拰鏈嶅姟鍣ㄥ疄鐜帮紝
鍚屾椂闄勫甫鏈夊熀浜庡懡浠よ鐨勫伐鍏凤紝浣垮緱閰嶇疆鍜岄儴缃蹭骇鍝佺骇鐨凾wisted搴旂敤鍙樺緱闈炲父鏂逛究銆�
=========================================绗笁閮ㄥ垎 鏁版嵁搴撳拰缂撳瓨锛�46棰橈級=====================================================
1銆佸垪涓惧父瑙佺殑鍏崇郴鍨嬫暟鎹簱鍜岄潪鍏崇郴鍨嬮兘鏈夐偅浜涳紵
鍏崇郴鍨嬶細Mysql / Oracle / SQL Server
闈炲叧绯诲瀷锛歳edis / MongoDB鈥�
2銆丮ySQL甯歌鏁版嵁搴撳紩鎿庡強姣旇緝锛�
MySQL鏁版嵁搴撲腑鐨勮〃寮曟搸涓�鑸父鐢ㄤ袱绉嶏細MyISAM鍜孖nnoDB
鍖哄埆锛�
MyISAM绫诲瀷鐨勬暟鎹枃浠舵湁涓変釜1.frm(缁撴瀯)銆�2.MYD锛堟暟鎹級銆�3.MYI锛堢储寮曪級
MyISAM绫诲瀷涓殑琛ㄦ暟鎹 鍒� 鏀归�熷害蹇紝涓嶆敮鎸佷簨鍔★紝娌℃湁InnoDB瀹夊叏銆�
InnoDB绫诲瀷鐨勬暟鎹枃浠跺彧鏈変竴涓� .frm
InnoDB绫诲瀷鐨勮〃鏁版嵁澧� 鍒� 鏀归�熷害娌℃湁MyISAM鐨勫揩锛屼絾鏀寔浜嬪姟锛岀浉瀵瑰畨鍏�
3銆佺畝杩版暟鎹笁澶ц寖寮忥紵
1銆佹瘡涓�鍒楀彧鏈変竴涓��
2銆佹瘡涓�琛岄兘鑳藉尯鍒嗐��
3銆佹瘡涓�涓〃閮戒笉鍖呭惈鍏朵粬琛ㄥ凡缁忓寘鍚殑闈炰富鍏抽敭瀛椾俊鎭��
4銆佷粈涔堟槸浜嬪姟锛烳ySQL濡備綍鏀寔浜嬪姟锛�
鍚屾椂瀵逛竴缁勬暟鎹繘琛屾搷浣滅殑璇彞灏辨垚涓轰簨鍔�
鍦� MySQL 涓彧鏈変娇鐢ㄤ簡 Innodb 鏁版嵁搴撳紩鎿庣殑鏁版嵁搴撴垨琛ㄦ墠鏀寔浜嬪姟銆�
5銆佺畝杩版暟鎹簱璁捐涓竴瀵瑰鍜屽瀵瑰鐨勫簲鐢ㄥ満鏅紵
6銆佸浣曞熀浜庢暟鎹簱瀹炵幇鍟嗗煄鍟嗗搧璁℃暟鍣紵
璁剧疆涓�涓晢鍝佽鏁扮殑鍒� 鑷姩閫掑涓�1(auto_increment)
7銆佸父瑙丼QL锛堝繀澶囷級
璇﹁姝︽矝榻愬崥瀹細https://www.cnblogs.com/wupeiqi/articles/5729934.html
8銆佺畝杩拌Е鍙戝櫒銆佸嚱鏁般�佽鍥俱�佸瓨鍌ㄨ繃绋嬶紵
瑙﹀彂鍣細鍒跺畾涓�涓猻ql鏉′欢鍜岃鍋氱殑浜嬪綋婊¤冻鐨勬椂鍊欒嚜鍔ㄨЕ鍙戝苟鎵ц瑕佸仛鐨勪簨
鍑芥暟锛堝瓨鍌ㄨ繃绋嬶級锛歁ysql鍌ㄥ瓨杩囩▼绠�鑰岃█涔嬪氨鏄竴缁勫凡缁忓ソ鐨勫懡浠わ紝闇�瑕佷娇鐢ㄧ殑鏃跺�欐嬁鍑烘潵鐢ㄥ氨鍙互
瑙嗗浘锛氬皢涓�涓啓濂界殑鏌ヨ璇彞灏佽璧锋潵 褰撹皟鐢ㄧ殑鏃剁湅鍒扮殑鏁版嵁灏辨槸婊¤冻鏉′欢鐨勬暟鎹� 涓嶇敤姣忔閮藉啓鍚屾牱鐨勪唬鐮�
9銆丮ySQL绱㈠紩绉嶇被
1銆佸敮涓�绱㈠紩:create unique index
2銆佷富閿储寮�:primary key
3銆佹櫘閫氱储寮�:create index on Tablename(鍒楃殑鍒楄〃)
4銆佸叏鏂囩储寮�:FULLTEXT
10銆佺储寮曞湪浠�涔堟儏鍐典笅閬靛惊鏈�宸﹀墠缂�鐨勮鍒欙紵
11銆佷富閿拰澶栭敭鐨勫尯鍒紵
1銆佷富閿紝鍞竴鏍囪瘑涓�鏉¤褰曪紝涓嶈兘閲嶅锛屼笉鍏佽涓虹┖锛涘閿紝琛ㄧ殑澶栭敭鏄彟涓�琛ㄧ殑涓婚敭锛屽閿彲浠ラ噸澶嶏紝鍙互鏄┖鍊�
2銆佷富閿紝鐢ㄦ潵淇濊瘉鏁版嵁瀹屾暣鎬э紱澶栭敭锛岀敤鏉ュ拰鍏朵粬琛ㄥ缓绔嬭仈绯�
3銆佷富閿彧鑳芥湁涓�涓紱涓�涓〃鍙互鏈夊涓閿�
12銆丮ySQL甯歌鐨勫嚱鏁帮紵
concat(s1,s2,鈥n) 杩炴帴s1,s2..Sn涓轰竴涓瓧绗︿覆
length(str) 杩斿洖鍊间负瀛楃涓瞫tr 鐨勯暱搴�
datediff(expr,expr2) 杩斿洖璧峰鏃堕棿鍜岀粨鏉熸椂闂寸殑闂撮殧澶╂暟
13銆佸垪涓� 鍒涘缓绱㈠紩浣嗘槸鏃犳硶鍛戒腑绱㈠紩鐨�8绉嶆儏鍐点��
14銆佸浣曞紑鍚參鏃ュ織鏌ヨ锛�
15銆佹暟鎹簱瀵煎叆瀵煎嚭鍛戒护锛堢粨鏋�+鏁版嵁锛夛紵
瀵煎嚭:
mysqldump -u root -p 搴撳悕 瀵煎嚭鐨勬枃浠�.sql
瀵煎叆:
mysql -u root -p 搴撳悕
16銆佹暟鎹簱浼樺寲鏂规锛�
涓虹粡甯告煡璇㈢殑瀛楁娣诲姞绱㈠紩
鍑忓皯澶栭敭鍏宠仈鏌ヨ
17銆乧har鍜寁archar鐨勫尯鍒紵
1銆乧har鐨勯暱搴︽槸鍥哄畾鐨勶紝鑰寁archar鐨勯暱搴︽槸鍙彉鐨�
2銆丆HAR鐨勬晥鐜囨瘮VARCHAR2鐨勬晥鐜囩◢楂�
3銆丆HAR(10)鑻ヨ緭鍏ユ暟鎹殑瀛楃鏁板皬浜�10锛屽垯绯荤粺鑷姩鍦ㄥ叾鍚庢坊鍔犵┖鏍兼潵濉弧璁惧畾濂界殑绌洪棿銆傝嫢杈撳叆鐨勬暟鎹繃闀匡紝灏嗕細鎴帀鍏惰秴鍑洪儴鍒嗐��
聽 VARCHAR(10)鏁版嵁绫诲瀷鐨勫瓨鍌ㄩ暱搴︿负瀹為檯鏁板�奸暱搴︺��
18銆佺畝杩癕ySQL鐨勬墽琛岃鍒掞紵
鏁版嵁搴撶殑鎵ц璁″垝閫氫織鐐硅灏辨槸锛屾暟鎹簱鏈嶅姟鍣ㄥ湪鎵цsql璇彞鐨勬椂鍊欙紝浼氬噯澶囧嚑濂楁柟妗堬紝鏈�鍚庨�夋嫨娑堣�楄祫婧愭渶灏忕殑閭d釜鏂规銆傚氨鏄墽琛岃鍒掋��
19銆佸湪瀵筺ame鍋氫簡鍞竴绱㈠紩鍓嶆彁涓嬶紝绠�杩颁互涓嬪尯鍒細
select * from tb where name = 鈥極ldboy-Wupeiqi鈥�
select * from tb where name = 鈥極ldboy-Wupeiqi鈥� limit 1
绗竴鏉¤鍙ヤ細鏌ヨ鎵�鏈� name = 'Oldboy-Wupeiqi'鐨勬暟鎹�
绗簩鏉¤鍙ュ彧浼氭煡璇㈢涓�涓鍚� name = 'Oldboy-Wupeiqi'鐨勬暟鎹�
20銆�1000w鏉℃暟鎹紝浣跨敤limit offset 鍒嗛〉鏃讹紝涓轰粈涔堣秺寰�鍚庣炕瓒婃參锛熷浣曡В鍐筹紵
褰撲竴涓暟鎹簱琛ㄨ繃浜庡簽澶э紝LIMIT offset, length涓殑offset鍊艰繃澶э紝鍒橲QL鏌ヨ璇彞浼氶潪甯哥紦鎱�
鍙互閫氳繃 澧炲姞order by锛屽苟涓攐rder by瀛楁闇�瑕佸缓绔嬬储寮曘��
21銆佷粈涔堟槸绱㈠紩鍚堝苟锛�
1銆佺储寮曞悎骞舵槸鎶婂嚑涓储寮曠殑鑼冨洿鎵弿鍚堝苟鎴愪竴涓储寮曘��
2銆佺储寮曞悎骞剁殑鏃跺�欙紝浼氬绱㈠紩杩涜浜ら泦锛屼氦闆嗘垨鑰呭厛浜ら泦鍐嶅苟闆嗘搷浣滐紝浠ヤ究鍚堝苟鎴愪竴涓储寮�
3銆佽繖浜涢渶瑕佸悎骞剁殑绱㈠紩鍙兘鏄竴涓〃鐨勩�備笉鑳藉澶氳〃杩涜绱㈠紩鍚堝苟
22銆佷粈涔堟槸瑕嗙洊绱㈠紩锛�
瑕嗙洊绱㈠紩鎸囷紝select鐨勬暟鎹垪鍙敤浠庣储寮曚腑灏辫兘鍙栧緱锛屼笉蹇呬粠鏁版嵁琛ㄤ腑璇诲彇锛屼篃灏辨槸璇存煡璇㈣琚墍浣跨敤鐨勭储寮曡鐩�
23銆佺畝杩版暟鎹簱璇诲啓鍒嗙锛�
瀵逛簬鏁版嵁瀛樺偍灞傞珮骞跺彂闂锛屾渶鍏堟兂鍒扮殑鍙兘灏辨槸璇诲啓鍒嗙锛屽湪缃戠珯璁块棶閲忓ぇ骞朵笖璇诲啓涓嶅钩鍧囩殑鎯呭喌涓嬶紝灏嗗瓨鍌ㄥ垎涓�
master锛宻lave涓ゅ彴锛屾墍鏈夌殑鍐欓兘璺敱鍒癿aster涓婏紝鎵�鏈夌殑璇婚兘璺敱鍒皊lave涓婏紝鐒跺悗master鍜宻lave鍚屾銆傚鏋滀竴鍙皊lave涓嶅锛�
鍙互鍔犲鍙帮紝姣斿涓�鍙癿aster锛�3鍙皊lave
24銆佺畝杩版暟鎹簱鍒嗗簱鍒嗚〃锛燂紙姘村钩銆佸瀭鐩达級
甯歌鐨勫垎搴撴柟寮忔湁姘村钩鎬у拰鍨傜洿鎬с�備竴鑸潵璇达紝灏辨槸鎸夌収鐢ㄦ埛灞炴�э紙鍩庡競鎴栬�匢D鐨刪ash锛夎繘琛屽垎搴擄紝鎴栬�呮寜鐓т笟鍔″姛鑳借繘琛屽垎搴�
姘村钩鍒嗗簱鏂瑰紡涓昏鏍规嵁鐢ㄦ埛灞炴�э紙濡傚煄甯傦級鎷嗗垎鐗╃悊鏁版嵁搴擄紝涓�绉嶅父瑙佺殑鏂瑰紡鏄皢鍏ㄧ渷鍒掑垎涓哄悇澶у尯
鍨傜洿鍒嗗簱鏂瑰紡锛氭牴鎹笟鍔$淮搴﹀拰鏁版嵁鐨勮闂噺绛夛紝杩涜鏁版嵁鐨勫垎绂伙紝鍓ョ涓哄涓暟鎹簱銆備緥濡傦紝灏嗕竴浜�
鍏敤鐨勯厤缃俊鎭瓨鍌ㄥ埌涓�涓暟鎹簱涓繘琛屽崟鐙淮鎶�
25銆乺edis鍜宮emcached姣旇緝锛�
1銆丷edis鍜孧emcache閮芥槸灏嗘暟鎹瓨鏀惧湪鍐呭瓨涓紝閮芥槸鍐呭瓨鏁版嵁搴撱�備笉杩噈emcache杩樺彲鐢ㄤ簬缂撳瓨鍏朵粬涓滆タ锛屼緥濡傚浘鐗囥�佽棰戠瓑绛夛紱
2銆丷edis涓嶄粎浠呮敮鎸佺畝鍗曠殑k/v绫诲瀷鐨勬暟鎹紝鍚屾椂杩樻彁渚沴ist锛宻et锛宧ash绛夋暟鎹粨鏋勭殑瀛樺偍锛�
3銆佽櫄鎷熷唴瀛樷�揜edis褰撶墿鐞嗗唴瀛樼敤瀹屾椂锛屽彲浠ュ皢涓�浜涘緢涔呮病鐢ㄥ埌鐨剉alue 浜ゆ崲鍒扮鐩橈紱
4銆佸瓨鍌ㄦ暟鎹畨鍏ㄢ�搈emcache鎸傛帀鍚庯紝鏁版嵁娌′簡锛況edis鍙互瀹氭湡淇濆瓨鍒扮鐩橈紙鎸佷箙鍖栵級锛�
5銆佺伨闅炬仮澶嶁�搈emcache鎸傛帀鍚庯紝鏁版嵁涓嶅彲鎭㈠; redis鏁版嵁涓㈠け鍚庡彲浠ラ�氳繃aof鎭㈠.
26銆乺edis涓暟鎹簱榛樿鏄灏戜釜db 鍙婁綔鐢紵
redis涓嬶紝鏁版嵁搴撴槸鐢变竴涓暣鏁扮储寮曟爣璇嗭紝鑰屼笉鏄敱涓�涓暟鎹簱鍚嶇О銆傞粯璁ゆ儏鍐典笅锛屼竴涓鎴风杩炴帴鍒版暟鎹簱0銆俽edis閰嶇疆鏂囦欢涓笅闈㈢殑鍙傛暟鏉ユ帶鍒舵暟鎹簱鎬绘暟锛�
/etc/redis/redis.conf
鏂囦欢涓紝鏈変釜閰嶇疆椤� databases = 16 //榛樿鏈�16涓暟鎹簱
27銆乸ython鎿嶄綔redis鐨勬ā鍧楋紵
r = redis.Redis(host="192.168.0.0", port=6379)
r.set("name", "ok")
print(r.get("name"))
28銆佸鏋渞edis涓殑鏌愪釜鍒楄〃涓殑鏁版嵁閲忛潪甯稿ぇ锛屽浣曞疄鐜板惊鐜樉绀烘瘡涓�涓�硷紵
鏌ヨ鍙栧嚭鍒楄〃鐨勫�艰鍚庝娇鐢╬ython寰幆
29銆乺edis濡備綍瀹炵幇涓讳粠澶嶅埗锛熶互鍙婃暟鎹悓姝ユ満鍒讹紵
鍦∕aster鍜孲lave浜掗�氫箣鍚庯紝棣栧厛锛孲lave浼氬彂閫乻ync鍚屾鎸囦护锛屽綋Master鏀跺埌鎸囦护鍚庯紝灏嗗湪鍚庡彴鍚姩瀛樼洏杩涚▼锛�
鍚屾椂鏀堕泦鎵�鏈夋潵鑷猄lave鐨勪慨鏀规暟鎹泦鐨勬寚浠や俊鎭紝褰撳悗鍙拌繘绋嬪畬鎴愪箣鍚庯紝Master灏嗗彂閫佸搴旂殑鏁版嵁搴撴枃浠跺埌瀵瑰簲鐨凷lave涓紝浠ュ畬鎴愪竴娆″畬鏁寸殑鍚屾宸ヤ綔銆�
鍏舵Slave鍦ㄦ帴鍙楀埌鏁版嵁搴撴枃浠朵箣鍚庯紝灏嗗叾瀛樼洏骞跺姞杞藉埌鍐呭瓨涓�傛渶鍚庯紝Master缁х画鏀堕泦淇敼鍛戒护鍜屾柊澧炵殑淇敼鎸囦护锛�
骞朵緷娆″彂閫佺粰Slave锛屽叾灏嗗湪鏈鎵ц杩欎簺鏁版嵁鐨勪慨鏀瑰懡浠わ紝浠庤�屾渶缁堣揪鍒版暟鎹悓姝ョ殑瀹炵幇銆�
30銆乺edis涓殑sentinel鐨勪綔鐢紵
Redis Sentinel 涓篟edis鎻愪緵浜嗛珮鍙敤鐨勫疄鐜般�傞�氫織鏉ヨ灏辨槸浣犲彲浠ラ儴缃蹭竴濂楁棤闇�浜轰负骞查鍗冲彲闃茬伨鐨凴edis鐜銆�
RS鍚屾椂涓哄鎴风鎻愪緵浜嗗叾浠栬濡傜洃鎺э紝閫氱煡鐨勫姛鑳姐��
31銆佸浣曞疄鐜皉edis闆嗙兢锛�
瀹樻柟cluster鏂规 =====> twemproxy浠g悊鏂规 =====> 鍝ㄥ叺妯″紡 =====> codis =====> 瀹㈡埛绔垎鐗�
32銆乺edis涓粯璁ゆ湁澶氬皯涓搱甯屾Ы锛�
鏈�2鐨�14娆℃柟涓搱甯屾Ы 16384涓�
33銆佺畝杩皉edis鐨勬湁鍝嚑绉嶆寔涔呭寲绛栫暐鍙婃瘮杈冿紵
rdb:蹇収褰㈠紡鏄洿鎺ユ妸鍐呭瓨涓殑鏁版嵁淇濆瓨鍒颁竴涓猟ump鏂囦欢涓紝瀹氭椂淇濆瓨锛屼繚瀛樼瓥鐣�
aof锛氭妸鎵�鏈夌殑瀵箁edis鐨勬湇鍔″櫒杩涜淇敼鐨勫懡浠ら兘瀛樺埌涓�涓枃浠堕噷锛屽懡浠ょ殑闆嗗悎
34銆佸垪涓緍edis鏀寔鐨勮繃鏈熺瓥鐣ャ��
瀹氭椂鍒犻櫎
鍦ㄨ缃甼ey鐨勮繃鏈熸椂闂寸殑鍚屾椂锛屼负璇ey鍒涘缓涓�涓畾鏃跺櫒锛岃瀹氭椂鍣ㄥ湪key鐨勮繃鏈熸椂闂存潵涓存椂锛屽key杩涜鍒犻櫎
鎯版�у垹闄ぢ�
key杩囨湡鐨勬椂鍊欎笉鍒犻櫎锛屾瘡娆′粠鏁版嵁搴撹幏鍙杒ey鐨勬椂鍊欏幓妫�鏌ユ槸鍚﹁繃鏈燂紝鑻ヨ繃鏈燂紝鍒欏垹闄わ紝杩斿洖null銆�
瀹氭湡鍒犻櫎
姣忛殧涓�娈垫椂闂存墽琛屼竴娆″垹闄�(鍦╮edis.conf閰嶇疆鏂囦欢璁剧疆hz锛�1s鍒锋柊鐨勯鐜�)杩囨湡key鎿嶄綔
35銆丮ySQL 閲屾湁 2000w 鏁版嵁锛宺edis 涓彧瀛� 20w 鐨勬暟鎹紝濡備綍淇濊瘉 redis 涓兘鏄儹鐐规暟鎹紵
LRU(鏈�杩戝皯鐢ㄧ殑娣樻卑)
鍗硆edis鐨勭紦瀛樻瘡鍛戒腑涓�娆�,灏辩粰鍛戒腑鐨勭紦瀛樺鍔犱竴瀹歵tl(杩囨湡鏃堕棿)(鏍规嵁鍏蜂綋鎯呭喌鏉ヨ瀹�, 姣斿10鍒嗛挓).
涓�娈垫椂闂村悗, 鐑暟鎹殑ttl閮戒細杈冨ぇ, 涓嶄細鑷姩澶辨晥, 鑰屽喎鏁版嵁鍩烘湰涓婅繃浜嗚瀹氱殑ttl灏遍┈涓婂け鏁堜簡.
36銆佸啓浠g爜锛屽熀浜巖edis鐨勫垪琛ㄥ疄鐜� 鍏堣繘鍏堝嚭銆佸悗杩涘厛鍑洪槦鍒椼�佷紭鍏堢骇闃熷垪銆�
鍏堣繘lpush keys values 鍏堝嚭 rpop keys
鍏堣繘lpush keys values 鍚庡嚭 lpop keys