{"id":17,"date":"2021-09-09T10:41:14","date_gmt":"2021-09-09T02:41:14","guid":{"rendered":"http:\/\/139.155.46.233\/?p=17"},"modified":"2021-09-09T10:41:14","modified_gmt":"2021-09-09T02:41:14","slug":"python%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"https:\/\/www.lucas88.cn\/?p=17","title":{"rendered":"Python\u57fa\u7840"},"content":{"rendered":"\n<p>\u672c\u8282\u5185\u5bb9<\/p>\n\n\n\n<p>1. \u51fd\u6570\u57fa\u672c\u8bed\u6cd5\u53ca\u7279\u6027<\/p>\n\n\n\n<p>2. \u53c2\u6570\u4e0e\u5c40\u90e8\u53d8\u91cf<\/p>\n\n\n\n<p>3. \u8fd4\u56de\u503c<\/p>\n\n\n\n<p>\u5d4c\u5957\u51fd\u6570<\/p>\n\n\n\n<p>4.\u9012\u5f52<\/p>\n\n\n\n<p>5.\u533f\u540d\u51fd\u6570<\/p>\n\n\n\n<p>6.\u51fd\u6570\u5f0f\u7f16\u7a0b\u4ecb\u7ecd<\/p>\n\n\n\n<p>7.\u9ad8\u9636\u51fd\u6570<\/p>\n\n\n\n<p>8.\u5185\u7f6e\u51fd\u6570<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6e29\u6545\u77e5\u65b0<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1. \u96c6\u5408<\/h4>\n\n\n\n<p>\u4e3b\u8981\u4f5c\u7528:&nbsp;<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u53bb\u91cd<\/li><li>\u5173\u7cfb\u6d4b\u8bd5\uff0c \u4ea4\u96c6\uff3c\u5dee\u96c6\uff3c\u5e76\u96c6\uff3c\u53cd\u5411(\u5bf9\u79f0)\u5dee\u96c6<\/li><\/ol>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n&gt;&gt;&gt; a = {1,2,3,4}\n&gt;&gt;&gt; b ={3,4,5,6}\n&gt;&gt;&gt; a\n{1, 2, 3, 4}\n&gt;&gt;&gt; type(a)\n&lt;class 'set'&gt;\n&gt;&gt;&gt; a.symmetric_difference(b)\n{1, 2, 5, 6}\n&gt;&gt;&gt; b.symmetric_difference(a)\n{1, 2, 5, 6}\n&gt;&gt;&gt;\n&gt;&gt;&gt;\n&gt;&gt;&gt; a.difference(b)\n{1, 2}\n&gt;&gt;&gt; a.union(b)\n{1, 2, 3, 4, 5, 6}\n&gt;&gt;&gt; a.issu\na.issubset(   a.issuperset(\n&gt;&gt;&gt; a.issubset(b)\nFalse\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">2. \u5143\u7ec4\u3000\u3000<\/h4>\n\n\n\n<p>\u53ea\u8bfb\u5217\u8868\uff0c\u53ea\u6709count, index 2 \u4e2a\u65b9\u6cd5<\/p>\n\n\n\n<p>\u4f5c\u7528\uff1a\u5982\u679c\u4e00\u4e9b\u6570\u636e\u4e0d\u60f3\u88ab\u4eba\u4fee\u6539\uff0c \u53ef\u4ee5\u5b58\u6210\u5143\u7ec4\uff0c\u6bd4\u5982\u8eab\u4efd\u8bc1\u5217\u8868<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">3. \u5b57\u5178<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">key-value\u5bf9<\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>\u7279\u6027\uff1a<\/li><li>\u65e0\u987a\u5e8f<\/li><li>\u53bb\u91cd<\/li><li>\u67e5\u8be2\u901f\u5ea6\u5feb\uff0c\u6bd4\u5217\u8868\u5feb\u591a\u4e86<\/li><li>\u6bd4list\u5360\u7528\u5185\u5b58\u591a<\/li><\/ol>\n\n\n\n<p>\u4e3a\u4ec0\u4e48\u4f1a\u67e5\u8be2\u901f\u5ea6\u4f1a\u5feb\u5462\uff1f\u56e0\u4e3a\u4ed6\u662fhash\u7c7b\u578b\u7684\uff0c\u90a3\u4ec0\u4e48\u662fhash\u5462\uff1f<\/p>\n\n\n\n<p>\u54c8\u5e0c\u7b97\u6cd5\u5c06\u4efb\u610f\u957f\u5ea6\u7684\u4e8c\u8fdb\u5236\u503c\u6620\u5c04\u4e3a\u8f83\u77ed\u7684\u56fa\u5b9a\u957f\u5ea6\u7684\u4e8c\u8fdb\u5236\u503c\uff0c\u8fd9\u4e2a\u5c0f\u7684\u4e8c\u8fdb\u5236\u503c\u79f0\u4e3a\u54c8\u5e0c\u503c\u3002\u54c8\u5e0c\u503c\u662f\u4e00\u6bb5\u6570\u636e\u552f\u4e00\u4e14\u6781\u5176\u7d27\u51d1\u7684\u6570\u503c\u8868\u793a\u5f62\u5f0f\u3002\u5982\u679c\u6563\u5217\u4e00\u6bb5\u660e\u6587\u800c\u4e14\u54ea\u6015\u53ea\u66f4\u6539\u8be5\u6bb5\u843d\u7684\u4e00\u4e2a\u5b57\u6bcd\uff0c\u968f\u540e\u7684\u54c8\u5e0c\u90fd\u5c06\u4ea7\u751f\u4e0d\u540c\u7684\u503c\u3002\u8981\u627e\u5230\u6563\u5217\u4e3a\u540c\u4e00\u4e2a\u503c\u7684\u4e24\u4e2a\u4e0d\u540c\u7684\u8f93\u5165\uff0c\u5728\u8ba1\u7b97\u4e0a\u662f\u4e0d\u53ef\u80fd\u7684\uff0c\u6240\u4ee5\u6570\u636e\u7684\u54c8\u5e0c\u503c\u53ef\u4ee5\u68c0\u9a8c\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002\u4e00\u822c\u7528\u4e8e\u5feb\u901f\u67e5\u627e\u548c\u52a0\u5bc6\u7b97\u6cd5<\/p>\n\n\n\n<p>dict\u4f1a\u628a\u6240\u6709\u7684key\u53d8\u6210hash \u8868\uff0c\u7136\u540e\u5c06\u8fd9\u4e2a\u8868\u8fdb\u884c\u6392\u5e8f\uff0c\u8fd9\u6837\uff0c\u4f60\u901a\u8fc7data[key]\u53bb\u67e5data\u5b57\u5178\u4e2d\u4e00\u4e2akey\u7684\u65f6\u5019\uff0cpython\u4f1a\u5148\u628a\u8fd9\u4e2akey hash\u6210\u4e00\u4e2a\u6570\u5b57\uff0c\u7136\u540e\u62ff\u8fd9\u4e2a\u6570\u5b57\u5230hash\u8868\u4e2d\u770b\u6ca1\u6709\u8fd9\u4e2a\u6570\u5b57\uff0c \u5982\u679c\u6709\uff0c\u62ff\u5230\u8fd9\u4e2akey\u5728hash\u8868\u4e2d\u7684\u7d22\u5f15\uff0c\u62ff\u5230\u8fd9\u4e2a\u7d22\u5f15\u53bb\u4e0e\u6b64key\u5bf9\u5e94\u7684value\u7684\u5185\u5b58\u5730\u5740\u90a3\u53d6\u503c\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n\n<p>\u4e0a\u9762\u4f9d\u7136\u6ca1\u56de\u7b54\u8fd9\u6837\u505a\u67e5\u627e\u4e00\u4e2a\u6570\u636e\u4e3a\u4ec0\u4e48\u4f1a\u6bd4\u5217\u8868\u5feb\uff0c\u5bf9\u4e0d\u5bf9\uff1f \u5475\u5475\uff0c\u7b49\u6211\u8bfe\u4e0a\u63ed\u6653\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">4. \u5b57\u7b26\u7f16\u7801<\/h4>\n\n\n\n<p><strong>\u5148\u8bf4python2<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>py2\u91cc\u9ed8\u8ba4\u7f16\u7801\u662fascii<\/li><li>\u6587\u4ef6\u5f00\u5934\u90a3\u4e2a\u7f16\u7801\u58f0\u660e\u662f\u544a\u8bc9\u89e3\u91ca\u8fd9\u4e2a\u4ee3\u7801\u7684\u7a0b\u5e8f \u4ee5\u4ec0\u4e48\u7f16\u7801\u683c\u5f0f \u628a\u8fd9\u6bb5\u4ee3\u7801\u8bfb\u5165\u5230\u5185\u5b58\uff0c\u56e0\u4e3a\u5230\u4e86\u5185\u5b58\u91cc\uff0c\u8fd9\u6bb5\u4ee3\u7801\u5176\u5b9e\u662f\u4ee5bytes\u4e8c\u8fdb\u5236\u683c\u5f0f\u5b58\u7684\uff0c\u4e0d\u8fc7\u5373\u4f7f\u662f2\u8fdb\u5236\u6d41\uff0c\u4e5f\u53ef\u4ee5\u6309\u4e0d\u540c\u7684\u7f16\u7801\u683c\u5f0f\u8f6c\u62102\u8fdb\u5236\u6d41\uff0c\u4f60\u61c2\u4e48\uff1f<\/li><li>\u5982\u679c\u5728\u6587\u4ef6\u5934\u58f0\u660e\u4e86#_*_coding:utf-8*_\uff0c\u5c31\u53ef\u4ee5\u5199\u4e2d\u6587\u4e86\uff0c \u4e0d\u58f0\u660e\u7684\u8bdd\uff0cpython\u5728\u5904\u7406\u8fd9\u6bb5\u4ee3\u7801\u65f6\u6309ascii\uff0c\u663e\u7136\u4f1a\u51fa\u9519\uff0c \u52a0\u4e86\u8fd9\u4e2a\u58f0\u660e\u540e\uff0c\u91cc\u9762\u7684\u4ee3\u7801\u5c31\u5168\u662futf-8\u683c\u5f0f\u4e86<\/li><li>\u5728\u6709#_*_coding:utf-8*_\u7684\u60c5\u51b5\u4e0b\uff0c\u4f60\u5728\u58f0\u660e\u53d8\u91cf\u5982\u679c\u5199\u6210name=u&#8221;\u5927\u4fdd\u5065&#8221;\uff0c\u90a3\u8fd9\u4e2a\u5b57\u7b26\u5c31\u662funicode\u683c\u5f0f\uff0c\u4e0d\u52a0\u8fd9\u4e2au,\u90a3\u4f60\u58f0\u660e\u7684\u5b57\u7b26\u4e32\u5c31\u662futf-8\u683c\u5f0f<\/li><li>utf-8 to gbk\u600e\u4e48\u8f6c\uff0cutf8\u5148decode\u6210unicode,\u518dencode\u6210gbk<\/li><\/ol>\n\n\n\n<p><strong>\u518d\u8bf4python3<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>py3\u91cc\u9ed8\u8ba4\u6587\u4ef6\u7f16\u7801\u5c31\u662futf-8,\u6240\u4ee5\u53ef\u4ee5\u76f4\u63a5\u5199\u4e2d\u6587\uff0c\u4e5f\u4e0d\u9700\u8981\u6587\u4ef6\u5934\u58f0\u660e\u7f16\u7801\u4e86\uff0c\u5e72\u7684\u6f02\u4eae<\/li><li>\u4f60\u58f0\u660e\u7684\u53d8\u91cf\u9ed8\u8ba4\u662funicode\u7f16\u7801\uff0c\u4e0d\u662futf-8, \u56e0\u4e3a\u9ed8\u8ba4\u5373\u662funicode\u4e86\uff08\u4e0d\u50cf\u5728py2\u91cc\uff0c\u4f60\u60f3\u76f4\u63a5\u58f0\u660e\u6210unicode\u8fd8\u5f97\u5728\u53d8\u91cf\u524d\u52a0\u4e2au\uff09, \u6b64\u65f6\u4f60\u60f3\u8f6c\u6210gbk\u7684\u8bdd\uff0c\u76f4\u63a5your_str.encode(&#8220;gbk&#8221;)\u5373\u53ef\u4ee5<\/li><li>\u4f46py3\u91cc\uff0c\u4f60\u5728your_str.encode(&#8220;gbk&#8221;)\u65f6\uff0c\u611f\u89c9\u597d\u50cf\u8fd8\u52a0\u4e86\u4e00\u4e2a\u52a8\u4f5c\uff0c\u5c31\u662f\u5c31\u662fencode\u7684\u6570\u636e\u53d8\u6210\u4e86bytes\u91cc\uff0c\u6211\u64e6\uff0c\u8fd9\u662f\u600e\u4e48\u4e2a\u60c5\u51b5\uff0c\u56e0\u4e3a\u5728py3\u91cc\uff0cstr and bytes\u505a\u4e86\u660e\u786e\u7684\u533a\u5206\uff0c\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3abytes\u5c31\u662f2\u8fdb\u5236\u6d41\uff0c\u4f60\u4f1a\u8bf4\uff0c\u6211\u770b\u5230\u7684\u4e0d\u662f010101\u8fd9\u6837\u76842\u8fdb\u5236\u5440\uff0c \u90a3\u662f\u56e0\u4e3apython\u4e3a\u4e86\u8ba9\u4f60\u80fd\u5bf9\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\u800c\u5728\u5185\u5b58\u7ea7\u522b\u53c8\u5e2e\u4f60\u505a\u4e86\u4e00\u5c42\u5c01\u88c5\uff0c\u5426\u5219\u8ba9\u4f60\u76f4\u63a5\u770b\u5230\u4e00\u58062\u8fdb\u5236\uff0c\u4f60\u80fd\u770b\u51fa\u54ea\u4e2a\u5b57\u7b26\u5bf9\u5e94\u54ea\u6bb52\u8fdb\u5236\u4e48\uff1f\u4ec0\u4e48\uff1f\u81ea\u5df1\u6362\u7b97\uff0c\u5f97\u4e86\u5427\uff0c\u4f60\u8fde\u8d85\u8fc72\u4f4d\u6570\u7684\u6570\u5b57\u52a0\u51cf\u8fd0\u7b97\u90fd\u8d39\u52b2\uff0c\u8fd8\u8fd8\u662f\u7701\u7701\u5fc3\u5427\u3002\u3000\u3000<\/li><li>\u90a3\u4f60\u8bf4\uff0c\u5728py2\u91cc\u597d\u50cf\u4e5f\u6709bytes\u5440\uff0c\u662f\u7684\uff0c\u4e0d\u8fc7py2\u91cc\u7684bytes\u53ea\u662f\u5bf9str\u505a\u4e86\u4e2a\u522b\u540d(python2\u91cc\u7684str\u5c31\u662fbytes, py3\u91cc\u7684str\u662funicode)\uff0c\u6ca1\u6709\u50cfpy3\u4e00\u6837\u7ed9\u4f60\u663e\u793a\u7684\u591a\u51fa\u6765\u4e00\u5c42\u5c01\u88c5\uff0c\u4f46\u5176\u5b9e\u5176\u5185\u90e8\u8fd8\u662f\u5c01\u88c5\u4e86\u7684\u3002 \u8fd9\u4e48\u8bb2\u5427\uff0c \u65e0\u8bba\u662f2\u8fd8\u662f\u4e09\uff0c \u4ece\u786c\u76d8\u5230\u5185\u5b58\uff0c\u6570\u636e\u683c\u5f0f\u90fd\u662f 010101\u4e8c\u8fdb\u5236\u5230&#8211;&gt;b&#8217;\\xe4\\xbd\\xa0\\xe5\\xa5\\xbd&#8217; bytes\u7c7b\u578b\uff0d\uff0d&gt;\u6309\u7167\u6307\u5b9a\u7f16\u7801\u8f6c\u6210\u4f60\u80fd\u770b\u61c2\u7684\u6587\u5b57<\/li><\/ol>\n\n\n\n<p>\u7f16\u7801\u5e94\u7528\u6bd4\u8f83\u591a\u7684\u573a\u666f\u5e94\u8be5\u662f\u722c\u866b\u4e86\uff0c\u4e92\u8054\u7f51\u4e0a\u5f88\u591a\u7f51\u7ad9\u7528\u7684\u7f16\u7801\u683c\u5f0f\u5f88\u6742\uff0c\u867d\u7136\u6574\u4f53\u8d8b\u5411\u90fd\u53d8\u6210utf-8\uff0c\u4f46\u73b0\u5728\u8fd8\u662f\u5f88\u6742\uff0c\u6240\u4ee5\u722c\u7f51\u9875\u65f6\u5c31\u9700\u8981\u4f60\u8fdb\u884c\u5404\u79cd\u7f16\u7801\u7684\u8f6c\u6362\uff0c\u4e0d\u8fc7\u751f\u6d3b\u6b63\u5728\u53d8\u7f8e\u597d\uff0c\u671f\u5f85\u4e00\u4e2a\u4e0d\u9700\u8981\u8f6c\u7801\u7684\u4e16\u754c\u3002<\/p>\n\n\n\n<p>\u6700\u540e\uff0c\u7f16\u7801is a piece of fucking shit, noboby likes it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1.\u51fd\u6570\u57fa\u672c\u8bed\u6cd5\u53ca\u7279\u6027<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u80cc\u666f\u63d0\u8981<\/h4>\n\n\n\n<p>\u73b0\u5728\u8001\u677f\u8ba9\u4f60\u5199\u4e00\u4e2a\u76d1\u63a7\u7a0b\u5e8f\uff0c\u76d1\u63a7\u670d\u52a1\u5668\u7684\u7cfb\u7edf\u72b6\u51b5\uff0c\u5f53cpu\uff3cmemory\uff3cdisk\u7b49\u6307\u6807\u7684\u4f7f\u7528\u91cf\u8d85\u8fc7\u9600\u503c\u65f6\u5373\u53d1\u90ae\u4ef6\u62a5\u8b66\uff0c\u4f60\u638f\u7a7a\u4e86\u6240\u6709\u7684\u77e5\u8bc6\u91cf\uff0c\u5199\u51fa\u4e86\u4ee5\u4e0b\u4ee3\u7801<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\nwhile True\uff1a\n    if cpu\u5229\u7528\u7387 &gt; 90%:\n        #\u53d1\u9001\u90ae\u4ef6\u63d0\u9192\n        \u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n        \u53d1\u9001\u90ae\u4ef6\n        \u5173\u95ed\u8fde\u63a5\n     \n    if \u786c\u76d8\u4f7f\u7528\u7a7a\u95f4 &gt; 90%:\n        #\u53d1\u9001\u90ae\u4ef6\u63d0\u9192\n        \u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n        \u53d1\u9001\u90ae\u4ef6\n        \u5173\u95ed\u8fde\u63a5\n     \n    if \u5185\u5b58\u5360\u7528 &gt; 80%:\n        #\u53d1\u9001\u90ae\u4ef6\u63d0\u9192\n        \u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n        \u53d1\u9001\u90ae\u4ef6\n        \u5173\u95ed\u8fde\u63a5\n<\/pre><\/div>\n\n\n<p>\u4e0a\u9762\u7684\u4ee3\u7801\u5b9e\u73b0\u4e86\u529f\u80fd\uff0c\u4f46\u5373\u4f7f\u662f\u90bb\u5c45\u8001\u738b\u4e5f\u770b\u51fa\u4e86\u7aef\u502a\uff0c\u8001\u738b\u4eb2\u5207\u7684\u6478\u4e86\u4e0b\u4f60\u5bb6\u513f\u5b50\u7684\u8138\u86cb\uff0c\u8bf4\uff0c\u4f60\u8fd9\u4e2a\u91cd\u590d\u4ee3\u7801\u592a\u591a\u4e86\uff0c\u6bcf\u6b21\u62a5\u8b66\u90fd\u8981\u91cd\u5199\u4e00\u6bb5\u53d1\u90ae\u4ef6\u7684\u4ee3\u7801\uff0c\u592alow\u4e86\uff0c\u8fd9\u6837\u5e72\u5b58\u57282\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u4ee3\u7801\u91cd\u590d\u8fc7\u591a\uff0c\u4e00\u4e2a\u52b2\u7684copy and paste\u4e0d\u7b26\u5408\u9ad8\u7aef\u7a0b\u5e8f\u5458\u7684\u6c14\u8d28<\/li><li>\u5982\u679c\u65e5\u540e\u9700\u8981\u4fee\u6539\u53d1\u90ae\u4ef6\u7684\u8fd9\u6bb5\u4ee3\u7801\uff0c\u6bd4\u5982\u52a0\u5165\u7fa4\u53d1\u529f\u80fd\uff0c\u90a3\u4f60\u5c31\u9700\u8981\u5728\u6240\u6709\u7528\u5230\u8fd9\u6bb5\u4ee3\u7801\u7684\u5730\u65b9\u90fd\u4fee\u6539\u4e00\u904d<\/li><\/ol>\n\n\n\n<p>\u4f60\u89c9\u5f97\u8001\u738b\u8bf4\u7684\u5bf9\uff0c\u4f60\u4e5f\u4e0d\u60f3\u5199\u91cd\u590d\u4ee3\u7801\uff0c\u4f46\u53c8\u4e0d\u77e5\u9053\u600e\u4e48\u641e\uff0c\u8001\u738b\u597d\u50cf\u770b\u51fa\u4e86\u4f60\u7684\u5fc3\u601d\uff0c\u6b64\u65f6\u4ed6\u62b1\u8d77\u4f60\u513f\u5b50\uff0c\u7b11\u7740\u8bf4\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u53ea\u9700\u8981\u628a\u91cd\u590d\u7684\u4ee3\u7801\u63d0\u53d6\u51fa\u6765\uff0c\u653e\u5728\u4e00\u4e2a\u516c\u5171\u7684\u5730\u65b9\uff0c\u8d77\u4e2a\u540d\u5b57\uff0c\u4ee5\u540e\u8c01\u60f3\u7528\u8fd9\u6bb5\u4ee3\u7801\uff0c\u5c31\u901a\u8fc7\u8fd9\u4e2a\u540d\u5b57\u8c03\u7528\u5c31\u884c\u4e86\uff0c\u5982\u4e0b<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndef \u53d1\u9001\u90ae\u4ef6(\u5185\u5bb9)\n    #\u53d1\u9001\u90ae\u4ef6\u63d0\u9192\n    \u8fde\u63a5\u90ae\u7bb1\u670d\u52a1\u5668\n    \u53d1\u9001\u90ae\u4ef6\n    \u5173\u95ed\u8fde\u63a5\n     \nwhile True\uff1a\n     \n    if cpu\u5229\u7528\u7387 &gt; 90%:\n        \u53d1\u9001\u90ae\u4ef6('CPU\u62a5\u8b66')\n     \n    if \u786c\u76d8\u4f7f\u7528\u7a7a\u95f4 &gt; 90%:\n        \u53d1\u9001\u90ae\u4ef6('\u786c\u76d8\u62a5\u8b66')\n     \n    if \u5185\u5b58\u5360\u7528 &gt; 80%:\n        \u53d1\u9001\u90ae\u4ef6('\u5185\u5b58\u62a5\u8b66')\n<\/pre><\/div>\n\n\n<p>\u4f60\u770b\u7740\u8001\u738b\u5199\u7684\u4ee3\u7801\uff0c\u6c14\u52bf\u6062\u5b8f\u3001\u78c5\u7934\u5927\u6c14\uff0c\u4ee3\u7801\u91cc\u900f\u9732\u7740\u4e00\u80a1\u5185\u655b\u7684\u50b2\u6c14\uff0c\u5fc3\u60f3\uff0c\u8001\u738b\u8fd9\u4e2a\u4eba\u771f\u662f\u4e0d\u4e00\u822c\uff0c\u7a81\u7136\u5bf9\u4ed6\u7684\u80cc\u666f\u66f4\u611f\u5174\u8da3\u4e86\uff0c\u95ee\u8001\u738b\uff0c\u8fd9\u4e9b\u82b1\u5f0f\u73a9\u6cd5\u4f60\u90fd\u662f\u600e\u4e48\u77e5\u9053\u7684\uff1f \u8001\u738b\u4eb2\u4e86\u4e00\u53e3\u4f60\u513f\u5b50\uff0c\u634b\u4e86\u634b\u4e0d\u5b58\u5728\u7684\u80e1\u5b50\uff0c\u6de1\u6de1\u7684\u8bb2\uff0c\u201c\u8001\u592b\uff0c\u5e74\u5c11\u65f6\uff0c\u5e08\u4ece\u4eac\u897f\u6c99\u6cb3\u6deb\u9b54\u94f6\u89d2\u5927\u738b \u201d\uff0c \u4f60\u4e00\u542c\u201c\u94f6\u89d2\u5927\u738b\u201d\u8fd9\u51e0\u4e2a\u5b57\uff0c\u4e0d\u7531\u7684\u5a07\u8eaf\u4e00\u9707\uff0c\u5fc3\u60f3\uff0c\u771fnb,\u602a\u4e0d\u5f97\u4ee3\u7801\u5199\u7684\u8fd9\u4e486, \u8fd9\u201c\u94f6\u89d2\u5927\u738b\u201d\u5f53\u5e74\u5728\u6c5f\u6e56\u4e0a\u53ef\u662f\u6570\u5f97\u7740\u7684\u54cd\u5f53\u5f53\u7684\u540d\u5b57\uff0c\u53ea\u53ef\u60dc\u540e\u671f\u7eb5\u6b32\u8fc7\u5ea6\uff0c\u5352\u4e8e\u516c\u51432016\u5e74\uff0c \u771f\u662f\u53ef\u60dc\u4e86\uff0c\u53ea\u7559\u4e0b\u5176\u54e5\u54e5\u5b64\u5b88\u5f53\u5e74\u5144\u5f1f\u4fe9\u4e00\u8d77\u6253\u4e0b\u6765\u7684\u6c5f\u5c71\u3002 \u6b64\u65f6\u4f60\u770b\u7740\u7684\u8001\u738b\u79bb\u5f00\u7684\u8eab\u5f71\uff0c\u611f\u89c9\u4f60\u513f\u5b50\u8ddf\u4ed6\u8d8a\u6765\u8d8a\u50cf\u4e86\u3002\u3002\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u51fd\u6570\u662f\u4ec0\u4e48?<\/h4>\n\n\n\n<p>\u51fd\u6570\u4e00\u8bcd\u6765\u6e90\u4e8e\u6570\u5b66\uff0c\u4f46\u7f16\u7a0b\u4e2d\u7684\u300c\u51fd\u6570\u300d\u6982\u5ff5\uff0c\u4e0e\u6570\u5b66\u4e2d\u7684\u51fd\u6570\u662f\u6709\u5f88\u5927\u4e0d\u540c\u7684\uff0c\u5177\u4f53\u533a\u522b\uff0c\u6211\u4eec\u540e\u9762\u4f1a\u8bb2\uff0c\u7f16\u7a0b\u4e2d\u7684\u51fd\u6570\u5728\u82f1\u6587\u4e2d\u4e5f\u6709\u5f88\u591a\u4e0d\u540c\u7684\u53eb\u6cd5\u3002\u5728BASIC\u4e2d\u53eb\u505asubroutine(\u5b50\u8fc7\u7a0b\u6216\u5b50\u7a0b\u5e8f)\uff0c\u5728Pascal\u4e2d\u53eb\u505aprocedure(\u8fc7\u7a0b)\u548cfunction\uff0c\u5728C\u4e2d\u53ea\u6709function\uff0c\u5728Java\u91cc\u9762\u53eb\u505amethod\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5b9a\u4e49: \u51fd\u6570\u662f\u6307\u5c06\u4e00\u7ec4\u8bed\u53e5\u7684\u96c6\u5408\u901a\u8fc7\u4e00\u4e2a\u540d\u5b57(\u51fd\u6570\u540d)\u5c01\u88c5\u8d77\u6765\uff0c\u8981\u60f3\u6267\u884c\u8fd9\u4e2a\u51fd\u6570\uff0c\u53ea\u9700\u8c03\u7528\u5176\u51fd\u6570\u540d\u5373\u53ef<\/h4>\n\n\n\n<p><strong>\u7279\u6027:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u51cf\u5c11\u91cd\u590d\u4ee3\u7801<\/li><li>\u4f7f\u7a0b\u5e8f\u53d8\u7684\u53ef\u6269\u5c55<\/li><li>\u4f7f\u7a0b\u5e8f\u53d8\u5f97\u6613\u7ef4\u62a4<\/li><\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">\u8bed\u6cd5\u5b9a\u4e49<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndef sayhi():#\u51fd\u6570\u540d\n    print(&quot;Hello, I'm nobody!&quot;)\n \nsayhi() #\u8c03\u7528\u51fd\u6570\n<\/pre><\/div>\n\n\n<p>\u53ef\u4ee5\u5e26\u53c2\u6570<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n#\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\na,b = 5,8\nc = a**b\nprint(c)\n \n \n#\u6539\u6210\u7528\u51fd\u6570\u5199\ndef calc(x,y):\n    res = x**y\n    return res #\u8fd4\u56de\u51fd\u6570\u6267\u884c\u7ed3\u679c\n \nc = calc(a,b) \uff03\u7ed3\u679c\u8d4b\u503c\u7ed9c\u53d8\u91cf\nprint(c)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">2.\u51fd\u6570\u53c2\u6570\u4e0e\u5c40\u90e8\u53d8\u91cf\u3000\u3000<\/h3>\n\n\n\n<p>\u5f62\u53c2\u53d8\u91cf\u53ea\u6709\u5728\u88ab\u8c03\u7528\u65f6\u624d\u5206\u914d\u5185\u5b58\u5355\u5143\uff0c\u5728\u8c03\u7528\u7ed3\u675f\u65f6\uff0c\u5373\u523b\u91ca\u653e\u6240\u5206\u914d\u7684\u5185\u5b58\u5355\u5143\u3002\u56e0\u6b64\uff0c\u5f62\u53c2\u53ea\u5728\u51fd\u6570\u5185\u90e8\u6709\u6548\u3002\u51fd\u6570\u8c03\u7528\u7ed3\u675f\u8fd4\u56de\u4e3b\u8c03\u7528\u51fd\u6570\u540e\u5219\u4e0d\u80fd\u518d\u4f7f\u7528\u8be5\u5f62\u53c2\u53d8\u91cf<\/p>\n\n\n\n<p>\u5b9e\u53c2\u53ef\u4ee5\u662f\u5e38\u91cf\u3001\u53d8\u91cf\u3001\u8868\u8fbe\u5f0f\u3001\u51fd\u6570\u7b49\uff0c\u65e0\u8bba\u5b9e\u53c2\u662f\u4f55\u79cd\u7c7b\u578b\u7684\u91cf\uff0c\u5728\u8fdb\u884c\u51fd\u6570\u8c03\u7528\u65f6\uff0c\u5b83\u4eec\u90fd\u5fc5\u987b\u6709\u786e\u5b9a\u7684\u503c\uff0c\u4ee5\u4fbf\u628a\u8fd9\u4e9b\u503c\u4f20\u9001\u7ed9\u5f62\u53c2\u3002\u56e0\u6b64\u5e94\u9884\u5148\u7528\u8d4b\u503c\uff0c\u8f93\u5165\u7b49\u529e\u6cd5\u4f7f\u53c2\u6570\u83b7\u5f97\u786e\u5b9a\u503c<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.lucas88.cn\/wp-content\/uploads\/2020\/10\/720333-20160805142111497-1945389864.png\" alt=\"\" class=\"wp-image-43\"\/><\/figure>\n\n\n\n<p><strong>\u9ed8\u8ba4\u53c2\u6570<\/strong><\/p>\n\n\n\n<p><strong>\u770b\u4e0b\u9762\u4ee3\u7801<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndef stu_register(name,age,country,course):\n    print(&quot;----\u6ce8\u518c\u5b66\u751f\u4fe1\u606f------&quot;)\n    print(&quot;\u59d3\u540d:&quot;,name)\n    print(&quot;age:&quot;,age)\n    print(&quot;\u56fd\u7c4d:&quot;,country)\n    print(&quot;\u8bfe\u7a0b:&quot;,course)\n \nstu_register(&quot;\u738b\u5c71\u70ae&quot;,22,&quot;CN&quot;,&quot;python_devops&quot;)\nstu_register(&quot;\u5f20\u53eb\u6625&quot;,21,&quot;CN&quot;,&quot;linux&quot;)\nstu_register(&quot;\u5218\u8001\u6839&quot;,25,&quot;CN&quot;,&quot;linux&quot;)\n<\/pre><\/div>\n\n\n<p>\u53d1\u73b0 country \u8fd9\u4e2a\u53c2\u6570 \u57fa\u672c\u90fd \u662f&#8221;CN&#8221;, \u5c31\u50cf\u6211\u4eec\u5728\u7f51\u7ad9\u4e0a\u6ce8\u518c\u7528\u6237\uff0c\u50cf\u56fd\u7c4d\u8fd9\u79cd\u4fe1\u606f\uff0c\u4f60\u4e0d\u586b\u5199\uff0c\u9ed8\u8ba4\u5c31\u4f1a\u662f \u4e2d\u56fd\uff0c \u8fd9\u5c31\u662f\u901a\u8fc7\u9ed8\u8ba4\u53c2\u6570\u5b9e\u73b0\u7684\uff0c\u628acountry\u53d8\u6210\u9ed8\u8ba4\u53c2\u6570\u975e\u5e38\u7b80\u5355<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<\/td><td><code>def<\/code>&nbsp;<code>stu_register(name,age,course,country<\/code><code>=<\/code><code>\"CN\"<\/code><code>):<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u8fd9\u6837\uff0c\u8fd9\u4e2a\u53c2\u6570\u5728\u8c03\u7528\u65f6\u4e0d\u6307\u5b9a\uff0c\u90a3\u9ed8\u8ba4\u5c31\u662fCN\uff0c\u6307\u5b9a\u4e86\u7684\u8bdd\uff0c\u5c31\u7528\u4f60\u6307\u5b9a\u7684\u503c\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u53e6\u5916\uff0c\u4f60\u53ef\u80fd\u6ce8\u610f\u5230\u4e86\uff0c\u5728\u628acountry\u53d8\u6210\u9ed8\u8ba4\u53c2\u6570\u540e\uff0c\u6211\u540c\u65f6\u628a\u5b83\u7684\u4f4d\u7f6e\u79fb\u5230\u4e86\u6700\u540e\u9762\uff0c\u4e3a\u4ec0\u4e48\u5462\uff1f\u3000\u3000<\/p><\/blockquote>\n\n\n\n<h4 class=\"wp-block-heading\">\u5173\u952e\u53c2\u6570<\/h4>\n\n\n\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b\uff0c\u7ed9\u51fd\u6570\u4f20\u53c2\u6570\u8981\u6309\u987a\u5e8f\uff0c\u4e0d\u60f3\u6309\u987a\u5e8f\u5c31\u53ef\u4ee5\u7528\u5173\u952e\u53c2\u6570\uff0c\u53ea\u9700\u6307\u5b9a\u53c2\u6570\u540d\u5373\u53ef\uff0c<em><strong>\u4f46\u8bb0\u4f4f\u4e00\u4e2a\u8981\u6c42\u5c31\u662f\uff0c\u5173\u952e\u53c2\u6570\u5fc5\u987b\u653e\u5728\u4f4d\u7f6e\u53c2\u6570\u4e4b\u540e\u3002<\/strong><\/em><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<\/td><td><code>stu_register(age<\/code><code>=<\/code><code>22<\/code><code>,name<\/code><code>=<\/code><code>'alex'<\/code><code>,course<\/code><code>=<\/code><code>\"python\"<\/code><code>,)<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>\u975e\u56fa\u5b9a\u53c2\u6570<\/strong><\/p>\n\n\n\n<p>\u82e5\u4f60\u7684\u51fd\u6570\u5728\u5b9a\u4e49\u65f6\u4e0d\u786e\u5b9a\u7528\u6237\u60f3\u4f20\u5165\u591a\u5c11\u4e2a\u53c2\u6570\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u975e\u56fa\u5b9a\u53c2\u6570<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndef stu_register(name,age,*args): # *args \u4f1a\u628a\u591a\u4f20\u5165\u7684\u53c2\u6570\u53d8\u6210\u4e00\u4e2a\u5143\u7ec4\u5f62\u5f0f\n    print(name,age,args)\n \nstu_register(&quot;Alex&quot;,22)\n#\u8f93\u51fa\n#Alex 22 () #\u540e\u9762\u8fd9\u4e2a()\u5c31\u662fargs,\u53ea\u662f\u56e0\u4e3a\u6ca1\u4f20\u503c,\u6240\u4ee5\u4e3a\u7a7a\n \nstu_register(&quot;Jack&quot;,32,&quot;CN&quot;,&quot;Python&quot;)\n#\u8f93\u51fa\n# Jack 32 ('CN', 'Python')\n<\/pre><\/div>\n\n\n<p>\u8fd8\u53ef\u4ee5\u6709\u4e00\u4e2a**kwargs<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndef stu_register(name,age,*args,**kwargs): # *kwargs \u4f1a\u628a\u591a\u4f20\u5165\u7684\u53c2\u6570\u53d8\u6210\u4e00\u4e2adict\u5f62\u5f0f\n    print(name,age,args,kwargs)\n \nstu_register(&quot;Alex&quot;,22)\n#\u8f93\u51fa\n#Alex 22 () {}#\u540e\u9762\u8fd9\u4e2a{}\u5c31\u662fkwargs,\u53ea\u662f\u56e0\u4e3a\u6ca1\u4f20\u503c,\u6240\u4ee5\u4e3a\u7a7a\n \nstu_register(&quot;Jack&quot;,32,&quot;CN&quot;,&quot;Python&quot;,sex=&quot;Male&quot;,province=&quot;ShanDong&quot;)\n#\u8f93\u51fa\n# Jack 32 ('CN', 'Python') {'province': 'ShanDong', 'sex': 'Male'}\n<\/pre><\/div>\n\n\n<p>\u5c40\u90e8\u53d8\u91cf<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\nname = &quot;Alex Li&quot;\n \ndef change_name(name):\n    print(&quot;before change:&quot;,name)\n    name = &quot;\u91d1\u89d2\u5927\u738b,\u4e00\u4e2a\u6709Tesla\u7684\u7537\u4eba&quot;\n    print(&quot;after change&quot;, name)\n \n \nchange_name(name)\n \nprint(&quot;\u5728\u5916\u9762\u770b\u770bname\u6539\u4e86\u4e48?&quot;,name)\n<\/pre><\/div>\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\nbefore change: Alex Li\nafter change \u91d1\u89d2\u5927\u738b,\u4e00\u4e2a\u6709Tesla\u7684\u7537\u4eba\n\u5728\u5916\u9762\u770b\u770bname\u6539\u4e86\u4e48? Alex Li\n<\/pre><\/div>\n\n\n<p><strong>\u5168\u5c40\u4e0e\u5c40\u90e8\u53d8\u91cf<\/strong>\u5728\u5b50\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u79f0\u4e3a\u5c40\u90e8\u53d8\u91cf\uff0c\u5728\u7a0b\u5e8f\u7684\u4e00\u5f00\u59cb\u5b9a\u4e49\u7684\u53d8\u91cf\u79f0\u4e3a\u5168\u5c40\u53d8\u91cf\u3002\u5168\u5c40\u53d8\u91cf\u4f5c\u7528\u57df\u662f\u6574\u4e2a\u7a0b\u5e8f\uff0c\u5c40\u90e8\u53d8\u91cf\u4f5c\u7528\u57df\u662f\u5b9a\u4e49\u8be5\u53d8\u91cf\u7684\u5b50\u7a0b\u5e8f\u3002\u5f53\u5168\u5c40\u53d8\u91cf\u4e0e\u5c40\u90e8\u53d8\u91cf\u540c\u540d\u65f6\uff1a\u5728\u5b9a\u4e49\u5c40\u90e8\u53d8\u91cf\u7684\u5b50\u7a0b\u5e8f\u5185\uff0c\u5c40\u90e8\u53d8\u91cf\u8d77\u4f5c\u7528\uff1b\u5728\u5176\u5b83\u5730\u65b9\u5168\u5c40\u53d8\u91cf\u8d77\u4f5c\u7528\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3.\u8fd4\u56de\u503c\u3000\u3000<\/h3>\n\n\n\n<p>\u8981\u60f3\u83b7\u53d6\u51fd\u6570\u7684\u6267\u884c\u7ed3\u679c\uff0c\u5c31\u53ef\u4ee5\u7528return\u8bed\u53e5\u628a\u7ed3\u679c\u8fd4\u56de<\/p>\n\n\n\n<p>\u6ce8\u610f:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u51fd\u6570\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u53ea\u8981\u9047\u5230return\u8bed\u53e5\uff0c\u5c31\u4f1a\u505c\u6b62\u6267\u884c\u5e76\u8fd4\u56de\u7ed3\u679c\uff0cso \u4e5f\u53ef\u4ee5\u7406\u89e3\u4e3a return \u8bed\u53e5\u4ee3\u8868\u7740\u51fd\u6570\u7684\u7ed3\u675f<\/li><li>\u5982\u679c\u672a\u5728\u51fd\u6570\u4e2d\u6307\u5b9areturn,\u90a3\u8fd9\u4e2a\u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e3aNone&nbsp;<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u5f3a\u884c\u63d2\u5165\u77e5\u8bc6\u70b9: \u5d4c\u5957\u51fd\u6570\u3000\u3000<\/h3>\n\n\n\n<p>\u770b\u4e0a\u9762\u7684\u6807\u9898\u7684\u610f\u601d\u662f\uff0c\u51fd\u6570\u8fd8\u80fd\u5957\u51fd\u6570\uff1fof course<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\nname = &quot;Alex&quot;\n \ndef change_name():\n    name = &quot;Alex2&quot;\n \n    def change_name2():\n        name = &quot;Alex3&quot;\n        print(&quot;\u7b2c3\u5c42\u6253\u5370&quot;,name)\n \n    change_name2() #\u8c03\u7528\u5185\u5c42\u51fd\u6570\n    print(&quot;\u7b2c2\u5c42\u6253\u5370&quot;,name)\n \n \nchange_name()\nprint(&quot;\u6700\u5916\u5c42\u6253\u5370&quot;,name)\n<\/pre><\/div>\n\n\n<p>\u6b64\u65f6\uff0c\u5728\u6700\u5916\u5c42\u8c03\u7528change_name2()\u4f1a\u51fa\u73b0\u4ec0\u4e48\u6548\u679c\uff1f<\/p>\n\n\n\n<p>\u6ca1\u9519\uff0c \u51fa\u9519\u4e86\uff0c \u4e3a\u4ec0\u4e48\u5462\uff1f<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u5d4c\u5957\u51fd\u6570\u7684\u7528\u6cd5\u4f1a\u4e86\uff0c\u4f46\u5b83\u6709\u4ec0\u4e48\u7528\u5462\uff1f\u4e0b\u8282\u8bfe\u63ed\u6653\u3002\u3002\u3002<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u9012\u5f52<\/h3>\n\n\n\n<p>\u5728\u51fd\u6570\u5185\u90e8\uff0c\u53ef\u4ee5\u8c03\u7528\u5176\u4ed6\u51fd\u6570\u3002\u5982\u679c\u4e00\u4e2a\u51fd\u6570\u5728\u5185\u90e8\u8c03\u7528\u81ea\u8eab\u672c\u8eab\uff0c\u8fd9\u4e2a\u51fd\u6570\u5c31\u662f\u9012\u5f52\u51fd\u6570\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndef calc(n):\n    print(n)\n    if int(n\/2) ==0:\n        return n\n    return calc(int(n\/2))\n \ncalc(10)\n \n\u8f93\u51fa\uff1a\n10\n5\n2\n1\n<\/pre><\/div>\n\n\n<p>\u9012\u5f52\u7279\u6027:<\/p>\n\n\n\n<p>1. \u5fc5\u987b\u6709\u4e00\u4e2a\u660e\u786e\u7684\u7ed3\u675f\u6761\u4ef6<\/p>\n\n\n\n<p>2. \u6bcf\u6b21\u8fdb\u5165\u66f4\u6df1\u4e00\u5c42\u9012\u5f52\u65f6\uff0c\u95ee\u9898\u89c4\u6a21\u76f8\u6bd4\u4e0a\u6b21\u9012\u5f52\u90fd\u5e94\u6709\u6240\u51cf\u5c11<\/p>\n\n\n\n<p>3. \u9012\u5f52\u6548\u7387\u4e0d\u9ad8\uff0c\u9012\u5f52\u5c42\u6b21\u8fc7\u591a\u4f1a\u5bfc\u81f4\u6808\u6ea2\u51fa\uff08\u5728\u8ba1\u7b97\u673a\u4e2d\uff0c\u51fd\u6570\u8c03\u7528\u662f\u901a\u8fc7\u6808\uff08stack\uff09\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u5b9e\u73b0\u7684\uff0c\u6bcf\u5f53\u8fdb\u5165\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\uff0c\u6808\u5c31\u4f1a\u52a0\u4e00\u5c42\u6808\u5e27\uff0c\u6bcf\u5f53\u51fd\u6570\u8fd4\u56de\uff0c\u6808\u5c31\u4f1a\u51cf\u4e00\u5c42\u6808\u5e27\u3002\u7531\u4e8e\u6808\u7684\u5927\u5c0f\u4e0d\u662f\u65e0\u9650\u7684\uff0c\u6240\u4ee5\uff0c\u9012\u5f52\u8c03\u7528\u7684\u6b21\u6570\u8fc7\u591a\uff0c\u4f1a\u5bfc\u81f4\u6808\u6ea2\u51fa\uff09<\/p>\n\n\n\n<p><em>\u5806\u6808\u626b\u76f2http:\/\/www.cnblogs.com\/lln7777\/archive\/2012\/03\/14\/2396164.html&nbsp;<\/em><\/p>\n\n\n\n<p>\u9012\u5f52\u51fd\u6570\u5b9e\u9645\u5e94\u7528\u6848\u4f8b\uff0c\u4e8c\u5206\u67e5\u627e<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndata = &#x5B;1, 3, 6, 7, 9, 12, 14, 16, 17, 18, 20, 21, 22, 23, 30, 32, 33, 35]\n \n \ndef binary_search(dataset,find_num):\n    print(dataset)\n \n    if len(dataset) &gt;1:\n        mid = int(len(dataset)\/2)\n        if dataset&#x5B;mid] == find_num:  #find it\n            print(&quot;\u627e\u5230\u6570\u5b57&quot;,dataset&#x5B;mid])\n        elif dataset&#x5B;mid] &gt; find_num :# \u627e\u7684\u6570\u5728mid\u5de6\u9762\n            print(&quot;\\033&#x5B;31;1m\u627e\u7684\u6570\u5728mid&#x5B;%s]\u5de6\u9762\\033&#x5B;0m&quot; % dataset&#x5B;mid])\n            return binary_search(dataset&#x5B;0:mid], find_num)\n        else:# \u627e\u7684\u6570\u5728mid\u53f3\u9762\n            print(&quot;\\033&#x5B;32;1m\u627e\u7684\u6570\u5728mid&#x5B;%s]\u53f3\u9762\\033&#x5B;0m&quot; % dataset&#x5B;mid])\n            return binary_search(dataset&#x5B;mid+1:],find_num)\n    else:\n        if dataset&#x5B;0] == find_num:  #find it\n            print(&quot;\u627e\u5230\u6570\u5b57\u5566&quot;,dataset&#x5B;0])\n        else:\n            print(&quot;\u6ca1\u7684\u5206\u4e86,\u8981\u627e\u7684\u6570\u5b57&#x5B;%s]\u4e0d\u5728\u5217\u8868\u91cc&quot; % find_num)\n \n \nbinary_search(data,66)\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">5. \u533f\u540d\u51fd\u6570&nbsp;<\/h3>\n\n\n\n<p>\u533f\u540d\u51fd\u6570\u5c31\u662f\u4e0d\u9700\u8981\u663e\u5f0f\u7684\u6307\u5b9a\u51fd\u6570<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n#\u8fd9\u6bb5\u4ee3\u7801\ndef calc(n):\n    return n**n\nprint(calc(10))\n \n#\u6362\u6210\u533f\u540d\u51fd\u6570\ncalc = lambda n:n**n\nprint(calc(10))\n<\/pre><\/div>\n\n\n<p>\u4f60\u4e5f\u8bb8\u4f1a\u8bf4\uff0c\u7528\u4e0a\u8fd9\u4e2a\u4e1c\u897f\u6ca1\u611f\u89c9\u6709\u6bdb\u65b9\u4fbf\u5440\uff0c \u3002\u3002\u3002\u3002\u5475\u5475\uff0c\u5982\u679c\u662f\u8fd9\u4e48\u7528\uff0c\u786e\u5b9e\u6ca1\u6bdb\u7ebf\u6539\u8fdb\uff0c\u4e0d\u8fc7\u533f\u540d\u51fd\u6570\u4e3b\u8981\u662f\u548c\u5176\u5b83\u51fd\u6570\u642d\u914d\u4f7f\u7528\u7684\u5462\uff0c\u5982\u4e0b<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\nres = map(lambda x:x**2,&#x5B;1,5,7,4,8])\nfor i in res:\n    print(i)\n<\/pre><\/div>\n\n\n<p>\u8f93\u51fa<\/p>\n\n\n\n<p>1<br>25<br>49<br>16<br>64<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.\u51fd\u6570\u5f0f\u7f16\u7a0b\u4ecb\u7ecd\u3000\u3000<\/h3>\n\n\n\n<p>\u51fd\u6570\u662fPython\u5185\u5efa\u652f\u6301\u7684\u4e00\u79cd\u5c01\u88c5\uff0c\u6211\u4eec\u901a\u8fc7\u628a\u5927\u6bb5\u4ee3\u7801\u62c6\u6210\u51fd\u6570\uff0c\u901a\u8fc7\u4e00\u5c42\u4e00\u5c42\u7684\u51fd\u6570\u8c03\u7528\uff0c\u5c31\u53ef\u4ee5\u628a\u590d\u6742\u4efb\u52a1\u5206\u89e3\u6210\u7b80\u5355\u7684\u4efb\u52a1\uff0c\u8fd9\u79cd\u5206\u89e3\u53ef\u4ee5\u79f0\u4e4b\u4e3a\u9762\u5411\u8fc7\u7a0b\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u3002\u51fd\u6570\u5c31\u662f\u9762\u5411\u8fc7\u7a0b\u7684\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u57fa\u672c\u5355\u5143\u3002<\/p>\n\n\n\n<p><strong>\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\u7684\u51fd\u6570\u8fd9\u4e2a\u672f\u8bed\u4e0d\u662f\u6307\u8ba1\u7b97\u673a\u4e2d\u7684\u51fd\u6570\uff08\u5b9e\u9645\u4e0a\u662fSubroutine\uff09\uff0c\u800c\u662f\u6307\u6570\u5b66\u4e2d\u7684\u51fd\u6570\uff0c\u5373\u81ea\u53d8\u91cf\u7684\u6620\u5c04\u3002\u4e5f\u5c31\u662f\u8bf4\u4e00\u4e2a\u51fd\u6570\u7684\u503c\u4ec5\u51b3\u5b9a\u4e8e\u51fd\u6570\u53c2\u6570\u7684\u503c\uff0c\u4e0d\u4f9d\u8d56\u5176\u4ed6\u72b6\u6001\u3002\u6bd4\u5982sqrt(x)\u51fd\u6570\u8ba1\u7b97x\u7684\u5e73\u65b9\u6839\uff0c\u53ea\u8981x\u4e0d\u53d8\uff0c\u4e0d\u8bba\u4ec0\u4e48\u65f6\u5019\u8c03\u7528\uff0c\u8c03\u7528\u51e0\u6b21\uff0c\u503c\u90fd\u662f\u4e0d\u53d8\u7684\u3002<\/strong><\/p>\n\n\n\n<p>Python\u5bf9\u51fd\u6570\u5f0f\u7f16\u7a0b\u63d0\u4f9b\u90e8\u5206\u652f\u6301\u3002\u7531\u4e8ePython\u5141\u8bb8\u4f7f\u7528\u53d8\u91cf\uff0c\u56e0\u6b64\uff0cPython\u4e0d\u662f\u7eaf\u51fd\u6570\u5f0f\u7f16\u7a0b\u8bed\u8a00\u3002<\/p>\n\n\n\n<p>\u4e00\u3001\u5b9a\u4e49<\/p>\n\n\n\n<p>\u7b80\u5355\u8bf4\uff0c&#8221;\u51fd\u6570\u5f0f\u7f16\u7a0b&#8221;\u662f\u4e00\u79cd<a href=\"http:\/\/en.wikipedia.org\/wiki\/Programming_paradigm\" target=\"_blank\" rel=\"noreferrer noopener\">&#8220;\u7f16\u7a0b\u8303\u5f0f&#8221;<\/a>\uff08programming paradigm\uff09\uff0c\u4e5f\u5c31\u662f\u5982\u4f55\u7f16\u5199\u7a0b\u5e8f\u7684\u65b9\u6cd5\u8bba\u3002<\/p>\n\n\n\n<p>\u4e3b\u8981\u601d\u60f3\u662f\u628a\u8fd0\u7b97\u8fc7\u7a0b\u5c3d\u91cf\u5199\u6210\u4e00\u7cfb\u5217\u5d4c\u5957\u7684\u51fd\u6570\u8c03\u7528\u3002\u4e3e\u4f8b\u6765\u8bf4\uff0c\u73b0\u5728\u6709\u8fd9\u6837\u4e00\u4e2a\u6570\u5b66\u8868\u8fbe\u5f0f\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u3000\u3000(1 + 2) * 3 &#8211; 4<\/p><\/blockquote>\n\n\n\n<p>\u4f20\u7edf\u7684\u8fc7\u7a0b\u5f0f\u7f16\u7a0b\uff0c\u53ef\u80fd\u8fd9\u6837\u5199\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u3000\u3000var a = 1 + 2;<\/p><p>\u3000\u3000var b = a * 3;<\/p><p>\u3000\u3000var c = b &#8211; 4;<\/p><\/blockquote>\n\n\n\n<p>\u51fd\u6570\u5f0f\u7f16\u7a0b\u8981\u6c42\u4f7f\u7528\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u628a\u8fd0\u7b97\u8fc7\u7a0b\u5b9a\u4e49\u4e3a\u4e0d\u540c\u7684\u51fd\u6570\uff0c\u7136\u540e\u5199\u6210\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u3000\u3000var result = subtract(multiply(add(1,2), 3), 4);<\/p><\/blockquote>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u518d\u6f14\u8fdb\u4ee5\u4e0b\uff0c\u53ef\u4ee5\u53d8\u6210\u8fd9\u6837<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>add(1,2).multiply(3).subtract(4)<\/p><\/blockquote>\n\n\n\n<p>\u8fd9\u57fa\u672c\u5c31\u662f\u81ea\u7136\u8bed\u8a00\u7684\u8868\u8fbe\u4e86\u3002\u518d\u770b\u4e0b\u9762\u7684\u4ee3\u7801\uff0c\u5927\u5bb6\u5e94\u8be5\u4e00\u773c\u5c31\u80fd\u660e\u767d\u5b83\u7684\u610f\u601d\u5427\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>merge([1,2],[3,4]).sort().search(&#8220;2&#8221;)<\/p><\/blockquote>\n\n\n\n<p>\u56e0\u6b64\uff0c\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u4ee3\u7801\u66f4\u5bb9\u6613\u7406\u89e3\u3002<\/p>\n\n\n\n<p>\u8981\u60f3\u5b66\u597d\u51fd\u6570\u5f0f\u7f16\u7a0b\uff0c\u4e0d\u8981\u73a9py,\u73a9Erlang,Haskell, \u597d\u4e86\uff0c\u6211\u53ea\u4f1a\u8fd9\u4e48\u591a\u4e86\u3002\u3002\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7.\u9ad8\u9636\u51fd\u6570<\/h3>\n\n\n\n<p>\u53d8\u91cf\u53ef\u4ee5\u6307\u5411\u51fd\u6570\uff0c\u51fd\u6570\u7684\u53c2\u6570\u80fd\u63a5\u6536\u53d8\u91cf\uff0c\u90a3\u4e48\u4e00\u4e2a\u51fd\u6570\u5c31\u53ef\u4ee5\u63a5\u6536\u53e6\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd9\u79cd\u51fd\u6570\u5c31\u79f0\u4e4b\u4e3a\u9ad8\u9636\u51fd\u6570\u3002<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\ndef add(x,y,f):\n    return f(x) + f(y)\n \n \nres = add(3,-6,abs)\nprint(res)\n<\/pre><\/div>\n\n\n<p>8. \u5185\u7f6e\u53c2\u6570\u3000\u3000<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.lucas88.cn\/wp-content\/uploads\/2020\/10\/v.png\" alt=\"\" class=\"wp-image-44\"\/><\/figure>\n\n\n\n<p>\u5185\u7f6e\u53c2\u6570\u8be6\u89e3 https:\/\/docs.python.org\/3\/library\/functions.html?highlight=built#ascii&nbsp;<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ==============Code==============; notranslate\" title=\"==============Code==============\">\n#compile\nf = open(&quot;\u51fd\u6570\u9012\u5f52.py&quot;)\ndata =compile(f.read(),'','exec')\nexec(data)\n\n\n#print\nmsg = &quot;\u53c8\u56de\u5230\u6700\u521d\u7684\u8d77\u70b9&quot;\nf = open(&quot;tofile&quot;,&quot;w&quot;)\nprint(msg,&quot;\u8bb0\u5fc6\u4e2d\u4f60\u9752\u6da9\u7684\u8138&quot;,sep=&quot;|&quot;,end=&quot;&quot;,file=f)\n\n\n# #slice\n# a = range(20)\n# pattern = slice(3,8,2)\n# for i in a&#x5B;pattern]: #\u7b49\u4e8ea&#x5B;3:8:2]\n#     print(i)\n#\n#\n\n\n#memoryview\n#usage:\n#&gt;&gt;&gt; memoryview(b'abcd')\n#&lt;memory at 0x104069648&gt;\n#\u5728\u8fdb\u884c\u5207\u7247\u5e76\u8d4b\u503c\u6570\u636e\u65f6\uff0c\u4e0d\u9700\u8981\u91cd\u65b0copy\u539f\u5217\u8868\u6570\u636e\uff0c\u53ef\u4ee5\u76f4\u63a5\u6620\u5c04\u539f\u6570\u636e\u5185\u5b58\uff0c\nimport time\nfor n in (100000, 200000, 300000, 400000):\n    data = b'x'*n\n    start = time.time()\n    b = data\n    while b:\n        b = b&#x5B;1:]\n    print('bytes', n, time.time()-start)\n\nfor n in (100000, 200000, 300000, 400000):\n    data = b'x'*n\n    start = time.time()\n    b = memoryview(data)\n    while b:\n        b = b&#x5B;1:]\n    print('memoryview', n, time.time()-start)\n\n\u51e0\u4e2a\u5185\u7f6e\u65b9\u6cd5\u7528\u6cd5\u63d0\u9192\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u672c\u8282\u4f5c\u4e1a<\/h3>\n\n\n\n<p>\u6709\u4ee5\u4e0b\u5458\u5de5\u4fe1\u606f\u8868<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/www.lucas88.cn\/wp-content\/uploads\/2020\/10\/2.png\" alt=\"\" class=\"wp-image-45\"\/><\/figure>\n\n\n\n<p>\u5f53\u7136\u6b64\u8868\u4f60\u5728\u6587\u4ef6\u5b58\u50a8\u65f6\u53ef\u4ee5\u8fd9\u6837\u8868\u793a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>1<\/td><td><code>1<\/code><code>,Alex Li,<\/code><code>22<\/code><code>,<\/code><code>13651054608<\/code><code>,IT,<\/code><code>2013<\/code><code>-<\/code><code>04<\/code><code>-<\/code><code>01<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u73b0\u9700\u8981\u5bf9\u8fd9\u4e2a\u5458\u5de5\u4fe1\u606f\u6587\u4ef6\uff0c\u5b9e\u73b0\u589e\u5220\u6539\u67e5\u64cd\u4f5c<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u53ef\u8fdb\u884c\u6a21\u7cca\u67e5\u8be2\uff0c\u8bed\u6cd5\u81f3\u5c11\u652f\u6301\u4e0b\u97623\u79cd:<ol><li>\u3000\u3000select name,age from staff_table where age &gt; 22<\/li><li>\u3000\u3000select &nbsp;* from staff_table where dept = &#8220;IT&#8221;<\/li><li>&nbsp; &nbsp; &nbsp; select &nbsp;* from staff_table where enroll_date like &#8220;2013&#8221;<\/li><li>\u67e5\u5230\u7684\u4fe1\u606f\uff0c\u6253\u5370\u540e\uff0c\u6700\u540e\u9762\u8fd8\u8981\u663e\u793a\u67e5\u5230\u7684\u6761\u6570&nbsp;<\/li><\/ol><\/li><li>\u53ef\u521b\u5efa\u65b0\u5458\u5de5\u7eaa\u5f55\uff0c\u4ee5phone\u505a\u552f\u4e00\u952e\uff0cstaff_id\u9700\u81ea\u589e<\/li><li>\u53ef\u5220\u9664\u6307\u5b9a\u5458\u5de5\u4fe1\u606f\u7eaa\u5f55\uff0c\u8f93\u5165\u5458\u5de5id\uff0c\u5373\u53ef\u5220\u9664<\/li><li>\u53ef\u4fee\u6539\u5458\u5de5\u4fe1\u606f\uff0c\u8bed\u6cd5\u5982\u4e0b:<ol><li>\u3000\u3000UPDATE staff_table SET dept=&#8221;Market&#8221; WHERE&nbsp;where dept = &#8220;IT&#8221;<\/li><\/ol><\/li><\/ol>\n\n\n\n<p><strong>&nbsp;\u6ce8\u610f\uff1a\u4ee5\u4e0a\u9700\u6c42\uff0c\u8981\u5145\u5206\u4f7f\u7528\u51fd\u6570\uff0c\u8bf7\u5c3d\u4f60\u7684\u6700\u5927\u9650\u5ea6\u6765\u51cf\u5c11\u91cd\u590d\u4ee3\u7801\uff01<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u8282\u5185\u5bb9 1. \u51fd\u6570\u57fa\u672c\u8bed\u6cd5\u53ca\u7279\u6027 2. \u53c2\u6570\u4e0e\u5c40\u90e8\u53d8\u91cf 3. \u8fd4\u56de\u503c \u5d4c\u5957\u51fd\u6570 4.\u9012\u5f52 5.\u533f\u540d\u51fd\u6570 6&#8230;. <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/www.lucas88.cn\/?p=17\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=17"}],"version-history":[{"count":1,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts\/17\/revisions"}],"predecessor-version":[{"id":18,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=\/wp\/v2\/posts\/17\/revisions\/18"}],"wp:attachment":[{"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lucas88.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}