{"id":28,"date":"2016-03-20T18:22:44","date_gmt":"2016-03-20T10:22:44","guid":{"rendered":"http:\/\/5x44.cn\/?p=28"},"modified":"2016-03-22T10:31:18","modified_gmt":"2016-03-22T02:31:18","slug":"%e7%ac%ac%e4%ba%8c%e7%ab%a0-%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%ef%bc%881%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=28","title":{"rendered":"\u7b2c\u4e8c\u7ae0 \u6570\u636e\u7c7b\u578b\uff081\uff09"},"content":{"rendered":"<p>\uff081\uff09PYTHON\u4e2d\u6bcf\u4e2a\u503c \u90fd\u6709\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\uff0c\u4f46\u5728PYTHON\u4e2d\u4e0d\u7528\u5b9a\u4e49\u5b83\u4eec\uff0c\u53d8\u91cf\u7684\u7c7b\u578b\u662f\u57fa\u4e8e\u6700\u521d\u7684\u8d4b\u503c\uff0cPYTHON\u4f1a\u5728\u5185\u90e8\u4fdd\u6301\u8ddf\u8e2a\u5b83\u4eec\u3002<br \/>\n\uff082\uff09PYTHON\u7684\u57fa\u672c\u7c7b\u578b\u6709\uff1a<br \/>\nBOOLEAN\uff1aTrue\u6216False\u4e24\u4e2a\u503c\u3002<br \/>\nNUMBER\uff1a\u53ef\u4ee5\u662f\u6574\u578b\uff0c\u6d6e\u70b9\uff0c\u5206\u6570\u6216\u590d\u6570\u3002<br \/>\nString\uff1a\u4e00\u4e32Unicode\u5b57\u7b26\u3002<br \/>\nByte\u548cbyte array\uff1a\u4e5f\u5c31\u662f\u4e00\u4e2aJPEG\u6587\u4ef6\uff08e.g. a JPEG image file\uff09<br \/>\nLIST\uff1a\u6709\u5e8f\u7684\u4e00\u4e32\u503c\u3002<br \/>\nTUPLE\uff1a\u4e00\u4e32\u4e0d\u53ef\u4fee\u6539\u7684\u6709\u5e8f\u503c\u3002<br \/>\nSET\uff1a\u4e00\u5806\u65e0\u5e8f\u7684\u503c\u3002<br \/>\nDICTIONARY\uff1a\u4e00\u5806\u65e0\u5e8f\u201c\u952e-\u503c\u201d\u5bf9\u3002<br \/>\n\uff08\u6240\u8c13\u6709\u5e8f\u3001\u65e0\u5e8f\u6211\u8ba4\u4e3a\u6307\u7684\u662f\u5efa\u7acb\u65f6\u503c\u7684\u987a\u5e8f\u3002\uff09<br \/>\n\uff083\uff09\u5e03\u5c14\u503c\u6709True\u548cFalse\u4e24\u79cd\uff0c\u5b83\u4eec\u53ef\u4ee5\u76f4\u63a5\u8d4b\u503c\u7ed9\u53d8\u91cf\u3002\u7531\u4e8e\u4e00\u4e9b\u4ecepython2\u9057\u7559\u4e0b\u6765\u7684\u95ee\u9898\uff0cTrue\u662f1\uff0cFalse\u662f0\u3002<br \/>\n\uff084\uff09\u5728\u67d0\u4e9b\u5730\u65b9\uff0cpython\u5e0c\u671b\u8868\u8fbe\u5f0f\u53bb\u8bc4\u4f30\u5e03\u5c14\u503c\uff0c\u8fd9\u4e9b\u5730\u65b9\u88ab\u53eb\u505a\u201c\u5e03\u5c14\u4e0a\u4e0b\u6587\u201d\u3002<br \/>\n\uff085\uff09\u5728\u201c\u5e03\u5c14\u4e0a\u4e0b\u6587\u201d\u4e2d\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u6709\u4e0d\u540c\u7684\u5e03\u5c14\u503c\u3002<br \/>\n\uff086\uff09number\u7c7b\u578b\u5305\u542b\u4e86int\u548cfloat\uff1a<br \/>\n&gt;&gt;&gt;type(2.0)<br \/>\n&lt;class &#8216;float&#8217;&gt;<br \/>\n&gt;&gt;&gt;type(2)<br \/>\n&lt;class &#8216;int&#8217;&gt;<br \/>\n\uff087\uff09\u4e24\u4e2aInt\u76f8\u52a0\u5f97\u5230int\u503c\uff1bint\u548cfloat\u76f8\u52a0\u5f97\u5230float\u2014\u2014\u53cd\u4e4b\u4ea6\u7136\u3002<br \/>\n\uff088\uff09\u53ef\u4ee5\u4f7f\u7528int()\u548cfloat()\u5bf9\u6570\u503c\u8fdb\u884c\u5f3a\u5236\u8f6c\u6362\u7c7b\u578b\uff0cint()\u51fd\u6570\u4f1a\u5c06\u6570\u622a\u65ad\uff0c\u800c\u4e0d\u662f\u5411\u4e0b\u53d6\u6574\u4e4b\u7c7b\u7684\u3002<br \/>\n\uff089\uff09\u6d6e\u70b9\u6570\u7cbe\u5ea6\u53ef\u8fbe15\u4f4d\uff0c\u800c\u6574\u6570\u7684\u53ef\u4ee5\u4efb\u610f\u5927\u3002<br \/>\n\uff0810\uff09\u6570\u5b57\u8fd0\u7b97\u7b26\uff1a<br \/>\n\/\uff1a\u6d6e\u70b9\u9664\u6cd5\uff0c\u65e0\u8bba\u5de6\u53f3\u64cd\u4f5c\u6570\u662f\u5426\u4e3a\u6d6e\u70b9\u578b\uff0c\u8fd4\u56de\u503c\u90fd\u662f\u6d6e\u70b9\u578b\u3002<br \/>\n\/\/\uff1a\u6574\u9664\u3002\u5982\u679c\u7ed3\u679c\u662f\u6b63\u6570\uff0c\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u662f\u628a\u5c0f\u6570\u70b9\u540e\u9762\u7684\u622a\u65ad\u4e86\uff1b\u5982\u679c\u7ed3\u679c\u662f\u8d1f\u6570\uff0c\u5c0f\u6570\u70b9\u540e\u4e00\u4f4d\u59cb\u7ec8\u8fdb\u4f4d\u5230\u6574\u6570\uff0c\u9664\u975e\u5c0f\u6570\u70b9\u540e\u65e0\u5c0f\u6570\u3002\u5982\u679c\u4e24\u4e2a\u6d6e\u70b9\u6570\u6574\u9664\uff0c\u89e3\u679c\u867d\u7136\u53d6\u6574\uff0c\u4f46\u662f\u7c7b\u578b\u4e3a\u6d6e\u70b9\u6570\u3002<br \/>\n7\/\/3 = 2;\u00a0 -7\/\/3 = -3<br \/>\n**\uff1a\u5e73\u65b9<br \/>\n%\uff1a\u6c42\u4f59\u6570<br \/>\n\uff0811\uff09\u8981\u4f7f\u7528\u5206\u6570\u7c7b\u578b\u5fc5\u987b\u5bfc\u5165fractions\u6a21\u5757\uff0c\u5b9a\u4e49\u5206\u6570\u5bf9\u8c61\u4f7f\u7528Fractions\u65b9\u6cd5\uff1a<br \/>\nx = fractions.Fractions(1,3)\uff0c\u5206\u5b50\u4e3a1\uff0c\u5206\u6bcd\u4e3a3<br \/>\n\uff0812\uff09\u53ef\u4ee5\u5bf9\u5206\u6570\u5bf9\u8c61\u4f7f\u7528\u6240\u6709\u7684\u6570\u5b66\u64cd\u4f5c\u7b26\uff0c\u5e76\u4e14\u5206\u6570\u5bf9\u8c61\u4f1a\u81ea\u52a8\u7ea6\u5206\u3002<br \/>\n&gt;&gt;&gt;x = fractions.Fractions(1, 3)<br \/>\n&gt;&gt;&gt;x*3<br \/>\nFraction(1, 1)<br \/>\n\uff0813\uff09\u4e0d\u80fd\u5efa\u7acb\u5206\u6bcd\u4e3a0\u7684\u5206\u6570\uff0c\u5982\u679c\u5206\u6bcd\u4e3a0\uff0c\u90a3\u4e48PYTHON\u4f1a\u5f15\u53d1ZeroDivisionError\u5f02\u5e38\u3002<br \/>\n\uff0814\uff09\u57fa\u672c\u7684\u4e09\u89d2\u51fd\u6570\u8981\u5bfc\u5165math\u6a21\u5757\u540e\u624d\u80fd\u4f7f\u7528,\u5982\uff1a<br \/>\n&gt;&gt;&gt;import math<br \/>\n&gt;&gt;&gt;math.pi<br \/>\n3.141592653589793<br \/>\n&gt;&gt;&gt;math.sin(math.pi\/2)<br \/>\n1.0<br \/>\n&gt;&gt;&gt;math.tan(math.pi\/4)<br \/>\n0.9999999999999999<br \/>\n\uff0815\uff09\u56e0\u4e3apython\u4e2d\u6ca1\u5b9a\u4e49\u7cbe\u51c6\u7684\u65e0\u7a77\u503c\uff0c\u6240\u4ee5tan(PI\/4)\u6ca1\u6709\u8fd4\u56de1.0\uff0c\u800c\u662f\u8fd4\u56de0.9999999999999999\u3002<br \/>\n\uff0816\uff09\u5b9a\u4e49\u7684\u5217\u8868\uff08list\uff09\u4f1a\u4fdd\u7559\u521d\u59cb\u987a\u5e8f\u3002<br \/>\n\uff0817\uff09\u4efb\u4f55\u975e\u7a7a\u5217\u8868\u7684\u7b2c\u4e00\u9879\u7d22\u5f15\u90fd\u662f0\uff0c\u5982\uff1aa_list[0]\uff1b\u4efb\u4f55\u975e\u7a7a\u5217\u8868\u7684\u6700\u540e\u4e00\u9879\u7d22\u5f15\u90fd \u662f-1\uff0c\u5982\uff1aa_list[-1]\uff1b\u6240\u4ee5\u5f53\u7d22\u5f15\u4e3a\u8d1f\u6570\u65f6\uff0c\u987a\u5e8f\u662f\u4ece\u6700\u540e\u4e00\u9879\u5411\u7b2c\u4e00\u9879\u6570\u7684\u987a\u5e8f\u3002<br \/>\n\uff0818\uff09 \u901a\u8fc7\u5192\u53f7\uff08\uff1a\uff09\u8fd4\u56de\u5217\u8868\u4e2d\u7684\u5b50\u96c6\uff0c\u5982\uff1aa_list[1:3]\uff08\u5305\u542b1\uff0c\u4f46\u4e0d\u5305\u542b3\uff09\uff0c\u5982\u679c\u6ca1\u5199\u7b2c\u4e00\u4e2a\u7d22\u5f15\uff0c\u5176\u9ed8\u6307\u5411\u4e00\u9879\uff0c\u5982\u679c\u6ca1\u5199\u7b2c\u4e8c\u4e2a\u7d22\u5f15\uff0c\u5176\u9ed8\u8ba4\u6307 \u5411\u6700\u540e\u4e00\u9879\u3002\u5982\u679c\u4e24\u4e2a\u7d22\u5f15\u9879\u90fd\u4e0d\u5199\u4f1a\u8fd4\u56de\u4e00\u4e2a\u539f\u6709list\u6240\u6709\u9879\u7684COPY\u3002\u6ce8\u610f\uff0c\u8fd9\u662f\u4e24\u4e2alist\uff0c\u800c\u4e0d\u662f\u6307\u5411\u540c\u4e00\u4e2alist\u7684\u4e24\u4e2a\u5bf9\u8c61\u3002<br \/>\n\uff0819\uff09\u5411\u5217\u8868\u6dfb\u52a0\u5143\u7d20\u76844\u79cd\u65b9\u6cd5\uff1a<br \/>\n1\uff09\u4f7f\u7528+\u53f7\uff0c\u5982\uff1aa_list + another_list\uff1b\u8fd4\u56de\u4e00\u4e2a\u65b0\u7684list<br \/>\n2\uff09insert\u65b9\u6cd5\uff0c\u5982\uff1aa_list.insert(0, value)\uff1b\u5728\u7d22\u5f15\u4f4d\u7f6e\u63d2\u5165value\uff0cvalue\u53ef\u4ee5\u662f\u4efb\u4f55\u503c\u2014\u2014number, string, list, franction\u7b49\u7b49<br \/>\n3\uff09append\u65b9\u6cd5\uff0c\u5982\uff1aa_list.append(value)\uff1b\u5728\u5f53\u524d\u5217\u8868\u7684\u6700\u540e\u6dfb\u52a0\u4e00\u4e2avalue\uff0c\u540c\u6837value\u53ef\u4ee5\u662f\u4efb\u4f55\u503c\u3002<br \/>\n4\uff09extend\u65b9\u6cd5\uff0c\u5982\uff1aa_list.extend(value)\uff1b\u5bf9\u5f53\u524d\u5217\u8868\u8fdb\u884c\u6269\u5c55\uff0c\u5f53value\u4e5f\u662f\u4e00\u4e2a\u5217\u8868\u65f6\u548c\u201c+\u201d\u64cd\u4f5c\u7b26\u7684\u6548\u679c\u4e00\u6837\u3002<br \/>\n\uff0820\uff09\u5217\u8868\u641c\u7d22\u6709\u4e09\u79cd\u65b9\u6cd5\uff1a<br \/>\n1\uff09a_list.count(value) #\u7edf\u8ba1\u6307\u5b9a\u7684value\u5728\u5217\u8868\u4e2d\u6709\u51e0\u4e2a\u3002<br \/>\n2\uff09value in a_list\u00a0 #value\u662f\u5426\u5728a_list\u4e2d\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u8981\u6bd4count\u7684\u901f\u5ea6\u5feb\u3002<br \/>\n3\uff09a_list.index(value)#value\u5728\u5217\u8868\u4e2d\u7684\u7d22\u5f15\uff08\u7b2c\u4e00\u4e2a\u627e\u5230\u7684\uff09\uff0c\u5b83\u8fd8\u6709\u7b2c\u4e8c\u4e2a\u53ef\u9009\u53c2\u6570\u2014\u2014\u4ece\u54ea\u91cc\u5f00\u59cb\uff0c\u5e76\u4e14\u8fd8\u6709\u7b2c\u4e09\u4e2a\u53ef\u9009\u53c2\u6570\u2014\u2014\u5728\u54ea\u91cc\u7ed3\u675f\uff08\u4e0d\u5305\u542b\u8be5\u503c\uff09\u3002\u5f53\u627e\u4e0d\u5230value\u65f6\u4f1a\u5f15\u53d1\u4e00\u4e2a\u5f02\u5e38\u3002<br \/>\n\uff0821)\u5220\u9664\u5217\u8868\u9879\u7684\u51e0\u79cd\u65b9\u6cd5\uff1a<br \/>\n1\uff09del a_list[index] #\u5220\u9664\u6307\u5b9a\u7d22\u5f15\u9879\uff0c\u4e4b\u540e\u6bcf\u4e00\u9879\u5de6\u79fb\u4e00\u4f4d\u3002<br \/>\n2\uff09a_list.remove(value)#\u5728\u5217\u8868\u4e2d\u5220\u9664\u7b2c\u4e00\u4e2a\u53d1\u73b0\u7684value\uff0c\u7136\u540e\u5de6\u79fb\u4e4b\u540e\u7684\u6bcf\u4e00\u9879\u3002\u5f53\u5220\u9664\u7684value\u4e0d\u5728\u5217\u8868\u4e2d\u65f6\uff0c\u4f1a\u5f15\u53d1\u4e00\u4e2aValueError\u5f02\u5e38\u3002<br \/>\n3\uff09a_list.pop()#\u4e0d\u5e26\u53c2\u6570\u65f6\u79fb\u9664\u6700\u540e\u4e00\u9879\u5e76\u8fd4\u56de\u8be5\u9879\u7684\u503c\uff1b\u4e5f\u53ef\u4ee5\u79fb\u9664\u6307\u5b9a\u7d22\u5f15\u9879\u7684\u503c\uff0c\u4e4b\u540e\u6bcf\u4e00\u9879\u5de6\u79fb\u4e00\u4f4d\u3002\u5982\u679c\u5217\u8868\u4e3a\u7a7a\uff0cpop()\u4f1a\u5f15\u53d1IndexError\u5f02\u5e38\u3002<br \/>\n\uff0822\uff09\u5728\u201c\u5e03\u5c14\u4e0a\u4e0b\u6587\u201d\u4e2d\uff0c\u5217\u8868\u4e3a\u7a7a\u65f6\u662ffalse\uff0c\u5217\u8868\u4e2d\u6709\u4efb\u4f55\u503c\u65f6\u4e3atrue\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\uff081\uff09PYTHON\u4e2d\u6bcf\u4e2a\u503c \u90fd\u6709\u4e00\u4e2a\u6570\u636e\u7c7b\u578b\uff0c\u4f46\u5728PYTHON\u4e2d\u4e0d\u7528\u5b9a\u4e49\u5b83\u4eec\uff0c\u53d8\u91cf\u7684\u7c7b\u578b\u662f\u57fa\u4e8e\u6700\u521d\u7684\u8d4b\u503c\uff0cPYTHON\u4f1a\u5728\u5185\u90e8\u4fdd\u6301\u8ddf\u8e2a\u5b83\u4eec\u3002 \uff082\uff09PYTHON&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=28\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[6],"class_list":["post-28","post","type-post","status-publish","format-standard","hentry","category-dive-into-python3","tag-it"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/28","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=28"}],"version-history":[{"count":1,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions"}],"predecessor-version":[{"id":29,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/28\/revisions\/29"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=28"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=28"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=28"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}