{"id":933103,"date":"2024-12-26T18:10:30","date_gmt":"2024-12-26T10:10:30","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/933103.html"},"modified":"2024-12-26T18:10:33","modified_gmt":"2024-12-26T10:10:33","slug":"python%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5size","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/933103.html","title":{"rendered":"python\u5982\u4f55\u5bfc\u5165size"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25070653\/dd9d9c28-b67f-4f72-977e-c7ba2b7c755b.webp\" alt=\"python\u5982\u4f55\u5bfc\u5165size\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a\u5728Python\u4e2d\uff0c\u5bfc\u5165size\u5c5e\u6027\u901a\u5e38\u662f\u6307\u83b7\u53d6\u67d0\u79cd\u6570\u636e\u7ed3\u6784\u7684\u5927\u5c0f\u6216\u7ef4\u5ea6\uff0c\u4f8b\u5982\u6570\u7ec4\u6216\u6570\u636e\u6846\u7684\u5927\u5c0f\u3002<strong>\u4f7f\u7528<code>len()<\/code>\u51fd\u6570\u3001<code>sys.getsizeof()<\/code>\u65b9\u6cd5\u3001Numpy\u5e93\u7684<code>numpy.size<\/code>\u5c5e\u6027<\/strong>\u662f\u83b7\u53d6\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u7ed3\u6784\u5927\u5c0f\u7684\u5e38\u7528\u65b9\u6cd5\u3002\u5176\u4e2d\uff0c<code>len()<\/code>\u51fd\u6570\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u7528\u6765\u83b7\u53d6\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\u4ee5\u53ca\u5176\u4ed6\u5bb9\u5668\u7c7b\u578b\u7684\u5143\u7d20\u6570\u91cf\u3002\u8fd9\u4f7f\u5f97<code>len()<\/code>\u51fd\u6570\u6210\u4e3a\u4e00\u4e2a\u7b80\u5355\u800c\u9ad8\u6548\u7684\u65b9\u6cd5\u6765\u83b7\u53d6Python\u6570\u636e\u7ed3\u6784\u7684\u5927\u5c0f\u3002\u5728\u4f7f\u7528\u65f6\uff0c\u53ea\u9700\u5c06\u76ee\u6807\u6570\u636e\u7ed3\u6784\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165<code>len()<\/code>\u51fd\u6570\u5373\u53ef\uff0c\u4f8b\u5982<code>len(list)<\/code>\u6765\u83b7\u53d6\u5217\u8868\u7684\u957f\u5ea6\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001PYTHON\u4e2d\u83b7\u53d6\u6570\u636e\u7ed3\u6784\u5927\u5c0f\u7684\u5e38\u7528\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>Python\u662f\u4e00\u95e8\u975e\u5e38\u7075\u6d3b\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5b83\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\u7ed3\u6784\u7684\u5927\u5c0f\u6216\u7ef4\u5ea6\u3002\u4e0d\u540c\u7684\u65b9\u6cd5\u9002\u7528\u4e8e\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\u548c\u4f7f\u7528\u573a\u666f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528<code>len()<\/code>\u51fd\u6570<\/strong><\/p>\n<\/p>\n<p><p><code>len()<\/code>\u51fd\u6570\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u51fd\u6570\uff0c\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u7684\u957f\u5ea6\u3002\u5b83\u9002\u7528\u4e8e\u591a\u79cd\u6570\u636e\u7c7b\u578b\uff0c\u5982\u5217\u8868\u3001\u5143\u7ec4\u3001\u5b57\u7b26\u4e32\u3001\u5b57\u5178\u7b49\u3002\u901a\u8fc7\u8c03\u7528<code>len()<\/code>\u51fd\u6570\u5e76\u5c06\u6570\u636e\u7ed3\u6784\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u5176\u5927\u5c0f\u3002\u4f8b\u5982\uff0c<code>len([1, 2, 3])<\/code>\u5c06\u8fd4\u56de3\u3002<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u83b7\u53d6\u5217\u8868\u7684\u957f\u5ea6\u5916\uff0c<code>len()<\/code>\u51fd\u6570\u8fd8\u53ef\u4ee5\u7528\u4e8e\u5176\u4ed6\u5bb9\u5668\u7c7b\u578b\uff0c\u5982\u5143\u7ec4\u548c\u5b57\u7b26\u4e32\u3002\u5bf9\u4e8e\u5b57\u5178\uff0c<code>len()<\/code>\u51fd\u6570\u8fd4\u56de\u952e-\u503c\u5bf9\u7684\u6570\u91cf\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>sys.getsizeof()<\/code>\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p><code>sys.getsizeof()<\/code>\u662fPython\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c\u7528\u4e8e\u83b7\u53d6\u5bf9\u8c61\u5728\u5185\u5b58\u4e2d\u7684\u5927\u5c0f\uff08\u4ee5\u5b57\u8282\u4e3a\u5355\u4f4d\uff09\u3002\u8981\u4f7f\u7528\u6b64\u65b9\u6cd5\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165<code>sys<\/code>\u6a21\u5757\u3002\u8be5\u65b9\u6cd5\u975e\u5e38\u6709\u7528\uff0c\u5c24\u5176\u662f\u5728\u9700\u8981\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u65f6\u3002<\/p>\n<\/p>\n<p><p><code>sys.getsizeof()<\/code>\u65b9\u6cd5\u4e0d\u4ec5\u9002\u7528\u4e8e\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff0c\u8fd8\u53ef\u4ee5\u7528\u4e8e\u81ea\u5b9a\u4e49\u5bf9\u8c61\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8be5\u65b9\u6cd5\u8fd4\u56de\u7684\u662f\u5bf9\u8c61\u7684\u6d45\u5c42\u5927\u5c0f\uff0c\u4e0d\u5305\u62ec\u5bf9\u8c61\u5f15\u7528\u7684\u5176\u4ed6\u5bf9\u8c61\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001NUMPY\u5e93\u4e2d\u7684<code>numpy.size<\/code>\u5c5e\u6027<\/p>\n<\/p>\n<p><p>Numpy\u662fPython\u4e2d\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u5e93\uff0c\u5c24\u5176\u64c5\u957f\u5904\u7406\u591a\u7ef4\u6570\u7ec4\u3002\u5bf9\u4e8eNumpy\u6570\u7ec4\uff0c<code>numpy.size<\/code>\u5c5e\u6027\u662f\u83b7\u53d6\u6570\u7ec4\u603b\u5143\u7d20\u6570\u91cf\u7684\u4e00\u4e2a\u4fbf\u6377\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Numpy\u5e93\u7b80\u4ecb<\/strong><\/p>\n<\/p>\n<p><p>Numpy\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u521b\u5efa\u548c\u64cd\u4f5c\u6570\u7ec4\u53ca\u77e9\u9635\u3002\u5b83\u4e0d\u4ec5\u652f\u6301\u57fa\u672c\u7684\u6570\u7ec4\u64cd\u4f5c\uff0c\u8fd8\u5305\u62ec\u8bb8\u591a\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u7ebf\u6027\u4ee3\u6570\u3001\u5085\u91cc\u53f6\u53d8\u6362\u548c\u968f\u673a\u6570\u751f\u6210\u3002\u5728\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u4e2d\uff0cNumpy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong><code>numpy.size<\/code>\u5c5e\u6027\u7684\u4f7f\u7528<\/strong><\/p>\n<\/p>\n<p><p><code>numpy.size<\/code>\u5c5e\u6027\u7528\u4e8e\u83b7\u53d6\u6570\u7ec4\u4e2d\u5143\u7d20\u7684\u603b\u6570\u91cf\u3002\u53ef\u4ee5\u901a\u8fc7<code>numpy.size(array)<\/code>\u7684\u5f62\u5f0f\u8c03\u7528\uff0c\u5176\u4e2d<code>array<\/code>\u662f\u76ee\u6807Numpy\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u5f62\u72b6\u4e3a(3, 4)\u7684\u6570\u7ec4\uff0c<code>numpy.size<\/code>\u5c06\u8fd4\u56de12\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u83b7\u53d6\u6570\u636e\u6846\u5927\u5c0f\u7684\u65b9\u6cd5<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0c\u6570\u636e\u6846\uff08DataFrame\uff09\u662f\u4e00\u79cd\u975e\u5e38\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\uff0c\u5c24\u5176\u662f\u5728\u4f7f\u7528Pandas\u5e93\u65f6\u3002\u4e86\u89e3\u5982\u4f55\u83b7\u53d6\u6570\u636e\u6846\u7684\u5927\u5c0f\u662f\u8fdb\u884c\u6570\u636e\u5206\u6790\u7684\u57fa\u7840\u6b65\u9aa4\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Pandas\u5e93\u7b80\u4ecb<\/strong><\/p>\n<\/p>\n<p><p>Pandas\u662fPython\u4e2d\u7528\u4e8e\u6570\u636e\u64cd\u4f5c\u548c\u5206\u6790\u7684\u4e00\u4e2a\u5f00\u6e90\u5e93\uff0c\u5b83\u63d0\u4f9b\u4e86\u6570\u636e\u6846\uff08DataFrame\uff09\u548c\u5e8f\u5217\uff08Series\uff09\u8fd9\u4e24\u79cd\u4e3b\u8981\u7684\u6570\u636e\u7ed3\u6784\u3002Pandas\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u9884\u5904\u7406\u548c\u6570\u636e\u53ef\u89c6\u5316\u7b49\u4efb\u52a1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u83b7\u53d6\u6570\u636e\u6846\u5927\u5c0f\u7684\u5e38\u7528\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u5728Pandas\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>DataFrame.shape<\/code>\u5c5e\u6027\u83b7\u53d6\u6570\u636e\u6846\u7684\u884c\u6570\u548c\u5217\u6570\u3002<code>DataFrame.shape<\/code>\u8fd4\u56de\u4e00\u4e2a\u5143\u7ec4\uff0c\u5305\u542b\u6570\u636e\u6846\u7684\u884c\u6570\u548c\u5217\u6570\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u5305\u542b5\u884c\u548c3\u5217\u7684\u6570\u636e\u6846\uff0c<code>DataFrame.shape<\/code>\u5c06\u8fd4\u56de(5, 3)\u3002<\/p>\n<\/p>\n<p><p>\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>len(DataFrame)<\/code>\u6765\u83b7\u53d6\u6570\u636e\u6846\u7684\u884c\u6570\uff0c\u4ee5\u53ca<code>len(DataFrame.columns)<\/code>\u6765\u83b7\u53d6\u5217\u6570\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528\u5176\u4ed6\u5e93\u83b7\u53d6\u6570\u636e\u5927\u5c0f<\/p>\n<\/p>\n<p><p>\u9664\u4e86Numpy\u548cPandas\uff0cPython\u4e2d\u8fd8\u6709\u5176\u4ed6\u5e93\u53ef\u4ee5\u7528\u4e8e\u83b7\u53d6\u6570\u636e\u5927\u5c0f\u3002\u8fd9\u4e9b\u5e93\u901a\u5e38\u7528\u4e8e\u7279\u5b9a\u7684\u5e94\u7528\u573a\u666f\uff0c\u5982\u56fe\u50cf\u5904\u7406\u548c<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528PIL\u5e93\u83b7\u53d6\u56fe\u50cf\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p>PIL\uff08Python Imaging Library\uff09\u662fPython\u4e2d\u7528\u4e8e\u56fe\u50cf\u5904\u7406\u7684\u4e00\u4e2a\u5e93\u3002\u901a\u8fc7\u4f7f\u7528PIL\u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u83b7\u53d6\u56fe\u50cf\u7684\u5927\u5c0f\uff08\u5bbd\u5ea6\u548c\u9ad8\u5ea6\uff09\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528PIL\u5e93\u83b7\u53d6\u56fe\u50cf\u5927\u5c0f\u7684\u6b65\u9aa4\u5305\u62ec\u5bfc\u5165PIL\u5e93\u3001\u6253\u5f00\u56fe\u50cf\u6587\u4ef6\uff0c\u5e76\u4f7f\u7528<code>Image.size<\/code>\u5c5e\u6027\u83b7\u53d6\u56fe\u50cf\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002\u8be5\u5c5e\u6027\u8fd4\u56de\u4e00\u4e2a\u5143\u7ec4\uff0c\u5305\u542b\u56fe\u50cf\u7684\u5bbd\u5ea6\u548c\u9ad8\u5ea6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Scikit-learn\u5e93\u83b7\u53d6\u6570\u636e\u96c6\u5927\u5c0f<\/strong><\/p>\n<\/p>\n<p><p>Scikit-learn\u662fPython\u4e2d\u7528\u4e8e\u673a\u5668\u5b66\u4e60\u7684\u4e00\u4e2a\u6d41\u884c\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u5185\u7f6e\u7684\u6570\u636e\u96c6\uff0c\u65b9\u4fbf\u7528\u6237\u8fdb\u884c\u6a21\u578b\u8bad\u7ec3\u548c\u6d4b\u8bd5\u3002\u901a\u8fc7\u8bbf\u95ee\u8fd9\u4e9b\u6570\u636e\u96c6\u7684<code>data<\/code>\u5c5e\u6027\uff0c\u53ef\u4ee5\u83b7\u53d6\u6570\u636e\u96c6\u7684\u5927\u5c0f\u3002<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Scikit-learn\u83b7\u53d6\u6570\u636e\u96c6\u5927\u5c0f\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>data.shape<\/code>\u5c5e\u6027\u6765\u83b7\u53d6\u6570\u636e\u96c6\u7684\u6837\u672c\u6570\u91cf\u548c\u7279\u5f81\u6570\u91cf\u3002\u8fd9\u5bf9\u4e8e\u4e86\u89e3\u6570\u636e\u96c6\u7684\u89c4\u6a21\u548c\u7ed3\u6784\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5185\u5b58\u4f18\u5316\u4e0e\u6027\u80fd\u63d0\u5347<\/p>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u548c\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u975e\u5e38\u91cd\u8981\u3002Python\u4e2d\u6709\u591a\u79cd\u6280\u672f\u53ef\u4ee5\u5e2e\u52a9\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u751f\u6210\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u751f\u6210\u5668\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u8fed\u4ee3\u5668\uff0c\u7528\u4e8e\u5728\u9700\u8981\u65f6\u751f\u6210\u6570\u636e\uff0c\u800c\u4e0d\u662f\u4e00\u6b21\u6027\u5c06\u6240\u6709\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u4f7f\u7528\u751f\u6210\u5668\u53ef\u4ee5\u663e\u8457\u964d\u4f4e\u5185\u5b58\u4f7f\u7528\uff0c\u5c24\u5176\u662f\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u3002<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>yield<\/code>\u5173\u952e\u5b57\u5b9a\u4e49\u751f\u6210\u5668\u51fd\u6570\u3002\u751f\u6210\u5668\u5728\u6bcf\u6b21\u8c03\u7528\u65f6\u8fd4\u56de\u4e00\u4e2a\u503c\uff0c\u5e76\u5728\u4e0b\u6b21\u8c03\u7528\u65f6\u6062\u590d\u6267\u884c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u7c7b\u578b\u4f18\u5316<\/strong><\/p>\n<\/p>\n<p><p>\u5408\u7406\u9009\u62e9\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u663e\u8457\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u3002\u4f8b\u5982\uff0c\u5728Numpy\u4e2d\uff0c\u4f7f\u7528<code>float32<\/code>\u4ee3\u66ff<code>float64<\/code>\u53ef\u4ee5\u51cf\u5c11\u5185\u5b58\u6d88\u8017\u3002\u7c7b\u4f3c\u5730\uff0c\u5728Pandas\u4e2d\uff0c\u53ef\u4ee5\u5c06\u6574\u6570\u7c7b\u578b\u4ece<code>int64<\/code>\u8f6c\u6362\u4e3a<code>int32<\/code>\u6216\u66f4\u5c0f\u7684\u7c7b\u578b\uff0c\u4ee5\u8282\u7701\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528\u8fd9\u4e9b\u4f18\u5316\u6280\u672f\u65f6\uff0c\u9700\u8981\u6743\u8861\u7cbe\u5ea6\u548c\u5185\u5b58\u6d88\u8017\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u7684\u6b63\u786e\u6027\u548c\u9ad8\u6548\u6027\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u603b\u7ed3\u4e0e\u5efa\u8bae<\/p>\n<\/p>\n<p><p>\u4e86\u89e3\u5982\u4f55\u5728Python\u4e2d\u5bfc\u5165\u548c\u83b7\u53d6\u6570\u636e\u7ed3\u6784\u7684\u5927\u5c0f\u662f\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u7684\u57fa\u7840\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528<code>len()<\/code>\u51fd\u6570\u3001<code>sys.getsizeof()<\/code>\u65b9\u6cd5\u3001\u4ee5\u53caNumpy\u548cPandas\u5e93\u4e2d\u7684\u76f8\u5173\u529f\u80fd\uff0c\u53ef\u4ee5\u9ad8\u6548\u83b7\u53d6\u6570\u636e\u5927\u5c0f\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u5206\u6790\u548c\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><p>\u6b64\u5916\uff0c\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u548c\u63d0\u5347\u7a0b\u5e8f\u6027\u80fd\u4e5f\u662f\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u9700\u8981\u8003\u8651\u7684\u91cd\u8981\u56e0\u7d20\u3002\u901a\u8fc7\u4f7f\u7528\u751f\u6210\u5668\u548c\u5408\u7406\u9009\u62e9\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u7a0b\u5e8f\u7684\u8fd0\u884c\u6548\u7387\u3002\u5728\u5b9e\u8df5\u4e2d\uff0c\u7ed3\u5408\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u548c\u6280\u672f\uff0c\u53ef\u4ee5\u6709\u6548\u5e94\u5bf9\u5404\u79cd\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u4efb\u52a1\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5bfc\u5165\u6a21\u5757\u6216\u5e93\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5bfc\u5165\u6a21\u5757\u6216\u5e93\u901a\u5e38\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u3002\u6bd4\u5982\uff0c\u5982\u679c\u4f60\u60f3\u4f7f\u7528<code>size<\/code>\u8fd9\u4e2a\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528<code>import size<\/code>\u3002\u5982\u679c\u9700\u8981\u5bfc\u5165\u7279\u5b9a\u7684\u529f\u80fd\u6216\u7c7b\uff0c\u53ef\u4ee5\u7528<code>from size import function_name<\/code>\u7684\u683c\u5f0f\u3002\u786e\u4fdd\u4f60\u7684\u6a21\u5757\u5728Python\u7684\u641c\u7d22\u8def\u5f84\u4e2d\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u68c0\u67e5\u5df2\u5bfc\u5165\u7684\u6a21\u5757\u7684\u53ef\u7528\u529f\u80fd\uff1f<\/strong><br \/>\u5728\u5bfc\u5165\u6a21\u5757\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684<code>dir()<\/code>\u51fd\u6570\u6765\u67e5\u770b\u6a21\u5757\u4e2d\u53ef\u7528\u7684\u529f\u80fd\u6216\u7c7b\u3002\u4f8b\u5982\uff0c\u8f93\u5165<code>dir(size)<\/code>\u5c06\u5217\u51fa\u6240\u6709\u5728<code>size<\/code>\u6a21\u5757\u4e2d\u5b9a\u4e49\u7684\u540d\u79f0\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>help(size)<\/code>\u53ef\u4ee5\u83b7\u5f97\u5173\u4e8e\u6a21\u5757\u7684\u8be6\u7ec6\u6587\u6863\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3Python\u4e2d\u5bfc\u5165\u6a21\u5757\u65f6\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u5982\u679c\u5728\u5bfc\u5165\u6a21\u5757\u65f6\u9047\u5230\u9519\u8bef\uff0c\u9996\u5148\u68c0\u67e5\u6a21\u5757\u662f\u5426\u5df2\u5b89\u88c5\u3002\u53ef\u4ee5\u901a\u8fc7<code>pip install size<\/code>\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\u3002\u5982\u679c\u6a21\u5757\u5b58\u5728\u4e8ePython\u73af\u5883\u4e2d\uff0c\u4f46\u4ecd\u65e0\u6cd5\u5bfc\u5165\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u6a21\u5757\u7684\u540d\u79f0\u62fc\u5199\u9519\u8bef\uff0c\u6216\u8005\u6a21\u5757\u4e0d\u5728Python\u7684\u641c\u7d22\u8def\u5f84\u4e2d\u3002\u901a\u8fc7\u68c0\u67e5<code>sys.path<\/code>\u53ef\u4ee5\u786e\u8ba4\u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a\u5728Python\u4e2d\uff0c\u5bfc\u5165size\u5c5e\u6027\u901a\u5e38\u662f\u6307\u83b7\u53d6\u67d0\u79cd\u6570\u636e\u7ed3\u6784\u7684\u5927\u5c0f\u6216\u7ef4\u5ea6\uff0c\u4f8b\u5982\u6570\u7ec4\u6216\u6570\u636e\u6846\u7684\u5927\u5c0f\u3002\u4f7f\u7528 [&hellip;]","protected":false},"author":3,"featured_media":933104,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/933103"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=933103"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/933103\/revisions"}],"predecessor-version":[{"id":933105,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/933103\/revisions\/933105"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/933104"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=933103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=933103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=933103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}