{"id":5487,"date":"2022-04-02T21:32:32","date_gmt":"2022-04-02T13:32:32","guid":{"rendered":"https:\/\/egonlin.com\/?p=5487"},"modified":"2022-04-02T21:32:32","modified_gmt":"2022-04-02T13:32:32","slug":"03-01-%e6%95%b0%e5%ad%97%e7%b1%bb%e5%9e%8b%e5%8f%8a%e5%85%b6%e6%93%8d%e4%bd%9c","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=5487","title":{"rendered":"03-01 \u6570\u5b57\u7c7b\u578b\u53ca\u5176\u64cd\u4f5c"},"content":{"rendered":"<h1>\u4e00\u3001\u6982\u8ff0<\/h1>\n<ul>\n<li>\u6574\u6570\u7c7b\u578b<\/li>\n<li>\u6d6e\u70b9\u6570\u7c7b\u578b<\/li>\n<li>\u590d\u6570\u7c7b\u578b<\/li>\n<li>\u6570\u503c\u8fd0\u7b97\u64cd\u4f5c\u7b26<\/li>\n<li>\u6570\u503c\u8fd0\u7b97\u51fd\u6570<\/li>\n<\/ul>\n<h1>\u4e8c\u3001\u6574\u6570\u7c7b\u578b<\/h1>\n<p>\u4e0e\u6570\u5b66\u4e2d\u6574\u6570\u7684\u6982\u5ff5\u4e00\u81f4<\/p>\n<ul>\n<li>\u53ef\u6b63\u53ef\u8d1f\uff0c\u6ca1\u6709\u53d6\u503c\u8303\u56f4\u9650\u5236<\/li>\n<li><code>pow(x,y)<\/code>\u51fd\u6570\uff1a\u8ba1\u7b97 ??xy\uff0c\u60f3\u7b97\u591a\u5927\u7b97\u591a\u5927<\/li>\n<\/ul>\n<pre><code class=\"language-python\">pow(2, 10)  # 1024\npow(2, pow(2, 5))  # 4294967296<\/code><\/pre>\n<h2>2.1 4\u79cd\u8fdb\u5236\u8868\u793a\u5f62\u5f0f<\/h2>\n<ul>\n<li>\u5341\u8fdb\u5236\uff1a1010, 99, -217<\/li>\n<li>\u4e8c\u8fdb\u5236\uff0c\u4ee50b\u62160B\u5f00\u5934\uff1a0b010, -0B101<\/li>\n<li>\u516b\u8fdb\u5236\uff0c\u4ee50o\u62160O\u5f00\u5934\uff1a0o123, -0O456<\/li>\n<li>\u5341\u516d\u8fdb\u5236\uff0c\u4ee50x\u62160X\u5f00\u5934\uff1a0x9a, -0X89<\/li>\n<\/ul>\n<p><strong>\u5173\u4e8ePython\u6574\u6570\uff0c\u5c31\u9700\u8981\u77e5\u9053\u8fd9\u4e9b\uff1a<\/strong><\/p>\n<ul>\n<li>\u6574\u6570\u65e0\u9650\u5236 <code>pow()<\/code><\/li>\n<li>4\u79cd\u8fdb\u5236\u8868\u793a\u5f62\u5f0f<\/li>\n<\/ul>\n<h1>\u4e09\u3001\u6d6e\u70b9\u6570\u7c7b\u578b<\/h1>\n<p>\u4e0e\u6570\u5b66\u4e2d\u5b9e\u6570\u7684\u6982\u5ff5\u4e00\u81f4<\/p>\n<ul>\n<li>\u5e26\u6709\u5c0f\u6570\u70b9\u53ca\u5c0f\u6570\u7684\u6570\u5b57<\/li>\n<li>\u6d6e\u70b9\u6570\u53d6\u503c\u8303\u56f4\u548c\u5c0f\u6570\u7cbe\u5ea6\u90fd\u5b58\u5728\u9650\u5236\uff0c\u4f46\u5e38\u89c4\u8ba1\u7b97\u53ef\u5ffd\u7565<\/li>\n<li>\u53d6\u503c\u8303\u56f4\u6570\u91cf\u7ea7\u7ea6\u221210308\u221210308\u81f31030810308\uff0c\u7cbe\u5ea6\u6570\u91cf\u7ea710\u22121610\u221216<\/li>\n<\/ul>\n<p>\u6d6e\u70b9\u6570\u95f4\u8fd0\u7b97\u5b58\u5728\u4e0d\u786e\u5b9a\u5c3e\u6570\uff0c\u4e0d\u662fbug<\/p>\n<pre><code class=\"language-python\">0.1 + 0.3  # 0.4\n0.1 + 0.2  # 0.30000000000000004<\/code><\/pre>\n<ul>\n<li><code>0.1<\/code>\uff1a53\u4f4d\u4e8c\u8fdb\u5236\u8868\u793a\u5c0f\u6570\u90e8\u5206\uff0c\u7ea6$10^{-16}$\n<ul>\n<li>0.00011001100110011001100110011001100110011001100110011010 (\u4e8c\u8fdb\u5236\u8868\u793a)<\/li>\n<li>0.1000000000000000055511151231257827021181583404541015625 (\u5341\u8fdb\u5236\u8868\u793a)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u4e8c\u8fdb\u5236\u8868\u793a\u5c0f\u6570\uff0c\u53ef\u4ee5\u65e0\u9650\u63a5\u8fd1\uff0c\u4f46\u4e0d\u5b8c\u5168\u76f8\u540c<\/p>\n<p><code>0.1 + 0.2<\/code>\uff1a\u7ed3\u679c\u65e0\u9650\u63a5\u8fd10.3\uff0c\u4f46\u53ef\u80fd\u5b58\u5728\u5c3e\u6570<\/p>\n<pre><code class=\"language-python\">0.1 + 0.2 == 0.3  # False\n\nround(0.1+0.2, 1) == 0.3  # True<\/code><\/pre>\n<h2>3.1 round()\u51fd\u6570<\/h2>\n<ul>\n<li><code>round(x, d)<\/code>\uff1a\u5bf9x\u56db\u820d\u4e94\u5165\uff0cd\u662f\u5c0f\u6570\u622a\u53d6\u4f4d\u6570<\/li>\n<li>\u6d6e\u70b9\u6570\u95f4\u8fd0\u7b97\u53ca\u6bd4\u8f83\u7528<code>round(<\/code>)\u51fd\u6570\u8f85\u52a9<\/li>\n<li>\u4e0d\u786e\u5b9a\u5c3e\u6570\u4e00\u822c\u53d1\u751f\u572810161016\u5de6\u53f3\uff0c<code>round()<\/code><\/li>\n<\/ul>\n<h2>3.2 \u79d1\u5b66\u8ba1\u6570\u6cd5\u8868\u793a\u6d6e\u70b9\u6570<\/h2>\n<ul>\n<li>\u4f7f\u7528\u5b57\u6bcde\u6216E\u4f5c\u4e3a\u5e42\u7684\u7b26\u53f7\uff0c\u4ee510\u4e3a\u57fa\u6570\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<code>&lt;a&gt;e&lt;b&gt;<\/code>\uff0c\u8868\u793a <code>a*10b<\/code><\/li>\n<li>\u4f8b\u5982\uff1a<code>4.3e-3<\/code> \u503c\u4e3a<code>0.0043<\/code>\uff0c<code>9.6E5<\/code> \u503c\u4e3a <code>960000.0<\/code><\/li>\n<\/ul>\n<p>\u5173\u4e8ePython\u6d6e\u70b9\u6570\uff0c\u9700\u8981\u77e5\u9053\u591a\u4e9b\u3002<\/p>\n<ul>\n<li>\u53d6\u503c\u8303\u56f4\u548c\u7cbe\u5ea6\u57fa\u672c\u65e0\u9650\u5236<\/li>\n<li>\u8fd0\u7b97\u5b58\u5728\u4e0d\u786e\u5b9a\u5c3e\u6570 round()<\/li>\n<li>\u79d1\u5b66\u8ba1\u6570\u6cd5\u8868\u793a<\/li>\n<\/ul>\n<h1>\u56db\u3001\u590d\u6570\u7c7b\u578b<\/h1>\n<p>\u4e0e\u6570\u5b66\u4e2d\u590d\u6570\u7684\u6982\u5ff5\u4e00\u81f4<\/p>\n<p>\u5982\u679c?2&#215;2 = -1\uff0c\u90a3\u4e48x\u7684\u503c\u4ec0\u4e48\uff1f<\/p>\n<ul>\n<li>\u5b9a\u4e49 <code>j = \u22121<\/code> \uff0c\u4ee5\u6b64\u4e3a\u57fa\u7840\uff0c\u6784\u5efa\u6570\u5b66\u4f53\u7cfb<\/li>\n<li><code>a+bj<\/code> \u88ab\u79f0\u4e3a\u590d\u6570\uff0c\u5176\u4e2d\uff0ca\u662f\u5b9e\u90e8\uff0cb\u662f\u865a\u90e8<\/li>\n<\/ul>\n<h2>4.1 \u590d\u6570\u5b9e\u4f8b<\/h2>\n<pre><code>z = 1.23e-4+5.6e+89j<\/code><\/pre>\n<ul>\n<li>\u5b9e\u90e8\u662f\u4ec0\u4e48\uff1f<code>z.real<\/code> \u83b7\u5f97\u5b9e\u90e8<\/li>\n<li>\u865a\u90e8\u662f\u4ec0\u4e48\uff1f<code>z.imag<\/code> \u83b7\u5f97\u865a\u90e8<\/li>\n<\/ul>\n<h1>\u4e94\u3001\u6570\u503c\u8fd0\u7b97\u64cd\u4f5c\u7b26<\/h1>\n<h2>5.1 \u4e00\u5143\u64cd\u4f5c\u7b26<\/h2>\n<p>\u64cd\u4f5c\u7b26\u662f\u5b8c\u6210\u8fd0\u7b97\u7684\u4e00\u79cd\u7b26\u53f7\u4f53\u7cfb<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u64cd\u4f5c\u7b26\u53ca\u4f7f\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">x+y<\/td>\n<td style=\"text-align: center;\">\u52a0\uff0cx\u4e0ey\u4e4b\u548c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x-y<\/td>\n<td style=\"text-align: center;\">\u51cf\uff0cx\u4e0ey\u4e4b\u5dee<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x*y<\/td>\n<td style=\"text-align: center;\">\u4e58\uff0cx\u4e0ey\u4e4b\u79ef<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x \/ y<\/td>\n<td style=\"text-align: center;\">\u9664\uff0cx\u4e0ey\u4e4b\u5546 <code>10\/3<\/code> \u7ed3\u679c\u662f3.3333333333333335<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x \/\/ y<\/td>\n<td style=\"text-align: center;\">\u6574\u6570\u9664\uff0cx\u4e0ey\u4e4b\u6574\u6570\u5546 <code>10\/\/3<\/code> \u7ed3\u679c\u662f3<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">+ x<\/td>\n<td style=\"text-align: center;\">x\u672c\u8eab<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">&#8211; y<\/td>\n<td style=\"text-align: center;\">x\u7684\u8d1f\u503c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x % y<\/td>\n<td style=\"text-align: center;\">\u4f59\u6570\uff0c\u6a21\u8fd0\u7b97\uff0c<code>10%3<\/code> \u7ed3\u679c\u662f1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">x ** y<\/td>\n<td style=\"text-align: center;\">\u5e42\u8fd0\u7b97\uff0cx\u7684y\u6b21\u5e42\uff0c??xy\uff0c\u5f53y\u662f\u5c0f\u6570\u65f6\uff0c\u5f00\u653e\u8fd0\u7b97\uff0c<code>10\\*\\*0.5<\/code>\u7ed3\u679c\u662f10\u203e\u203e\u203e\u221a10<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>5.2 \u4e8c\u5143\u64cd\u4f5c\u7b26<\/h2>\n<p>\u4e8c\u5143\u64cd\u4f5c\u7b26\u6709\u5bf9\u5e94\u7684\u589e\u5f3a\u8d4b\u503c\u64cd\u4f5c\u7b26<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u589e\u5f3a\u64cd\u4f5c\u7b26\u53ca\u4f7f\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">x op= y<\/td>\n<td style=\"text-align: center;\">\u5373 <code>x = x op y<\/code>\uff0c\u5176\u4e2d\uff0cop\u4e3a\u4e8c\u5143\u64cd\u4f5c\u7b26<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4e8c\u5143\u64cd\u4f5c\u7b26\u6709\u4ee5\u4e0b\u8fd9\u4e9b\uff1a<code>x += y<\/code>\uff0c <code>x -= y<\/code>\uff0c <code>x *= y<\/code>\uff0c <code>x \/= y<\/code>\uff0c <code>x \/\/ y<\/code>\uff0c <code>x %= y<\/code>\uff0c <code>x **= y<\/code><\/p>\n<pre><code><\/code><\/pre>\n<h2>5.3 \u6570\u5b57\u7c7b\u578b\u7684\u5173\u7cfb<\/h2>\n<p>\u7c7b\u578b\u95f4\u53ef\u8fdb\u884c\u6df7\u5408\u8fd0\u7b97\uff0c\u751f\u6210\u7ed3\u679c\u4e3a&quot;\u6700\u5bbd&quot;\u7c7b\u578b<\/p>\n<ul>\n<li>\u4e09\u79cd\u7c7b\u578b\u5b58\u5728\u4e00\u79cd\u9010\u6e10&quot;\u6269\u5c55&quot;\u6216&quot;\u53d8\u5bbd&quot;\u7684\u5173\u7cfb\uff1a\u6574\u6570 -&gt; \u6d6e\u70b9\u6570 -&gt; \u590d\u6570<\/li>\n<li>\u4f8b\u5982\uff1a<code>123 + 4.0 = 127.0<\/code> (\u6574\u6570+\u6d6e\u70b9\u6570 = \u6d6e\u70b9\u6570)<\/li>\n<\/ul>\n<h1>\u516d\u3001\u6570\u503c\u8fd0\u7b97\u51fd\u6570<\/h1>\n<p>\u4e00\u4e9b\u4ee5\u51fd\u6570\u5f62\u5f0f\u63d0\u4f9b\u7684\u6570\u503c\u8fd0\u7b97\u529f\u80fd<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u51fd\u6570\u53ca\u4f7f\u7528<\/th>\n<th style=\"text-align: center;\">\u63cf\u8ff0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">abs(x)<\/td>\n<td style=\"text-align: center;\">\u7edd\u5bf9\u503c\uff0cx\u7684\u7edd\u5bf9\u503c\uff0cabs(-10.01) \u7ed3\u679c\u4e3a 10.01<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">divmod(x,y)<\/td>\n<td style=\"text-align: center;\">\u5546\u4f59\uff0c(x\/\/y, x%y)\uff0c\u540c\u65f6\u8f93\u51fa\u5546\u548c\u4f59\u6570\uff0cdivmod(10, 3) \u7ed3\u679c\u4e3a (3, 1)<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">pow(x, y[, z])<\/td>\n<td style=\"text-align: center;\">\u5e42\u4f59\uff0c(x**y)%z\uff0c[..]\u8868\u793a\u53c2\u6570z\u53ef\u7701\u7565\uff0cpow(3, pow(3, 99), 10000) \u7ed3\u679c\u4e3a 4587<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">round(x[, d])<\/td>\n<td style=\"text-align: center;\">\u56db\u820d\u4e94\u5165\uff0cd\u662f\u4fdd\u7559\u5c0f\u6570\u4f4d\u6570\uff0c\u9ed8\u8ba4\u503c\u4e3a0\uff0cround(-10.123, 2) \u7ed3\u679c\u4e3a -10.12<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">max(?1,?2,\u22ef,??x1,x2,\u22ef,xn)<\/td>\n<td style=\"text-align: center;\">\u6700\u5927\u503c\uff0c\u8fd4\u56de?1,?2,\u22ef,??x1,x2,\u22ef,xn\u4e2d\u7684\u6700\u5927\u503c\uff0cn\u4e0d\u9650\uff0cmax(1, 9, 5, 4 3) \u7ed3\u679c\u4e3a 9<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">min(?1,?2,\u22ef,??x1,x2,\u22ef,xn)<\/td>\n<td style=\"text-align: center;\">\u6700\u5c0f\u503c\uff0c\u8fd4\u56de?1,?2,\u22ef,??x1,x2,\u22ef,xn\u4e2d\u7684\u6700\u5c0f\u503c\uff0cn\u4e0d\u9650\uff0cmin(1, 9, 5, 4 3) \u7ed3\u679c\u4e3a 1<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">int(x)<\/td>\n<td style=\"text-align: center;\">\u5c06x\u53d8\u6210\u6574\u6570\uff0c\u820d\u5f03\u5c0f\u6570\u90e8\u5206\uff0cint(123.45) \u7ed3\u679c\u4e3a123\uff1b int(&quot;123&quot;) \u7ed3\u679c\u4e3a123<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">float(x)<\/td>\n<td style=\"text-align: center;\">\u5c06x\u53d8\u6210\u6d6e\u70b9\u6570\uff0c\u589e\u52a0\u5c0f\u6570\u90e8\u5206\uff0cfloat(12) \u7ed3\u679c\u4e3a12.0\uff1b float(&quot;1.23&quot;) \u7ed3\u679c\u4e3a1.23<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">complex(x)<\/td>\n<td style=\"text-align: center;\">\u5c06x\u53d8\u6210\u590d\u6570\uff0c\u589e\u52a0\u865a\u6570\u90e8\u5206\uff0ccomplex(4) \u7ed3\u679c\u4e3a 4 + 0j<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u4e03\u3001\u5c0f\u7ed3<\/h1>\n<ul>\n<li>\u6574\u6570\u7c7b\u578b\u7684\u65e0\u9650\u8303\u56f4\u53ca4\u79cd\u8fdb\u5236\u8868\u793a<\/li>\n<li>\u6d6e\u70b9\u6570\u7c7b\u578b\u7684\u8fd1\u4f3c\u65e0\u9650\u8303\u56f4\u3001\u5c0f\u5c3e\u6570\u53ca\u79d1\u5b66\u8ba1\u6570\u6cd5<\/li>\n<li>+\u3001-\u3001*\u3001\/\u3001\/\/\u3001%\u3001**\u3001\u4e8c\u5143\u589e\u5f3a\u8d4b\u503c\u64cd\u4f5c\u7b26<\/li>\n<li>abs()\u3001divmod()\u3001pow()\u3001round()\u3001max()\u3001min()<\/li>\n<li>int()\u3001float()\u3001complex()<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6982\u8ff0 \u6574\u6570\u7c7b\u578b \u6d6e\u70b9\u6570\u7c7b\u578b \u590d\u6570\u7c7b\u578b \u6570\u503c\u8fd0\u7b97\u64cd\u4f5c\u7b26 \u6570\u503c\u8fd0\u7b97\u51fd\u6570 \u4e8c\u3001\u6574\u6570\u7c7b\u578b \u4e0e\u6570\u5b66\u4e2d\u6574\u6570\u7684\u6982\u5ff5\u4e00\u81f4  [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5431,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[371,374],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5487"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5487"}],"version-history":[{"count":0,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/5487\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/media\/5431"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}