{"id":162522,"date":"2019-11-25T10:45:23","date_gmt":"2019-11-25T02:45:23","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=162522"},"modified":"2019-10-25T09:46:53","modified_gmt":"2019-10-25T01:46:53","slug":"number-of-python3","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/number-of-python3.html","title":{"rendered":"Python3\u57fa\u672c\u6570\u636e\u4e4b Number\uff08\u6570\u5b57\uff09"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nPython \u4e2d\u7684\u53d8\u91cf\u4e0d\u9700\u8981\u58f0\u660e\u3002\u6bcf\u4e2a\u53d8\u91cf\u5728\u4f7f\u7528\u524d\u90fd\u5fc5\u987b\u8d4b\u503c\uff0c\u53d8\u91cf\u8d4b\u503c\u4ee5\u540e\u8be5\u53d8\u91cf\u624d\u4f1a\u88ab\u521b\u5efa\u3002
\n\u5728 Python \u4e2d\uff0c\u53d8\u91cf\u5c31\u662f\u53d8\u91cf\uff0c\u5b83\u6ca1\u6709\u7c7b\u578b\uff0c\u6211\u4eec\u6240\u8bf4\u7684\"\u7c7b\u578b\"\u662f\u53d8\u91cf\u6240\u6307\u7684\u5185\u5b58\u4e2d\u5bf9\u8c61\u7684\u7c7b\u578b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

Python3 \u652f\u6301 int\u3001float\u3001bool\u3001complex\uff08\u590d\u6570\uff09\u3002<\/strong><\/p>\n

\u5728Python 3\u91cc\uff0c\u53ea\u6709\u4e00\u79cd\u6574\u6570\u7c7b\u578b int\uff0c\u8868\u793a\u4e3a\u957f\u6574\u578b\uff0c\u6ca1\u6709 python2 \u4e2d\u7684 Long\u3002<\/p>\n

\u50cf\u5927\u591a\u6570\u8bed\u8a00\u4e00\u6837\uff0c\u6570\u503c\u7c7b\u578b\u7684\u8d4b\u503c\u548c\u8ba1\u7b97\u90fd\u662f\u5f88\u76f4\u89c2\u7684\u3002<\/p>\n

\u5185\u7f6e\u7684 type() \u51fd\u6570\u53ef\u4ee5\u7528\u6765\u67e5\u8be2\u53d8\u91cf\u6240\u6307\u7684\u5bf9\u8c61\u7c7b\u578b\u3002<\/p>\n

>>> a, b, c, d = 20, 5.5, True, 4+3j\r\n>>> print(type(a), type(b), type(c), type(d))\r\n <\/class> <\/class> <\/class><\/class><\/pre>\n

\u6b64\u5916\u8fd8\u53ef\u4ee5\u7528 isinstance \u6765\u5224\u65ad\uff1a<\/p>\n

\u5b9e\u4f8b\r\n>>>a = 111\r\n>>> isinstance(a, int)\r\nTrue\r\n>>><\/pre>\n

isinstance \u548c type \u7684\u533a\u522b\u5728\u4e8e\uff1a<\/p>\n

type()\u4e0d\u4f1a\u8ba4\u4e3a\u5b50\u7c7b\u662f\u4e00\u79cd\u7236\u7c7b\u7c7b\u578b\u3002
\nisinstance()\u4f1a\u8ba4\u4e3a\u5b50\u7c7b\u662f\u4e00\u79cd\u7236\u7c7b\u7c7b\u578b\u3002<\/p>\n

>>> class A:\r\n...     pass\r\n... \r\n>>> class B(A):\r\n...     pass\r\n... \r\n>>> isinstance(A(), A)\r\nTrue\r\n>>> type(A()) == A \r\nTrue\r\n>>> isinstance(B(), A)\r\nTrue\r\n>>> type(B()) == A\r\nFalse<\/pre>\n

\u6ce8\u610f\uff1a\u5728 Python2 \u4e2d\u662f\u6ca1\u6709\u5e03\u5c14\u578b\u7684\uff0c\u5b83\u7528\u6570\u5b57 0 \u8868\u793a False\uff0c\u7528 1 \u8868\u793a True\u3002\u5230 Python3 \u4e2d\uff0c\u628a True \u548c False \u5b9a\u4e49\u6210\u5173\u952e\u5b57\u4e86\uff0c\u4f46\u5b83\u4eec\u7684\u503c\u8fd8\u662f 1 \u548c 0\uff0c\u5b83\u4eec\u53ef\u4ee5\u548c\u6570\u5b57\u76f8\u52a0\u3002<\/p>\n

\u5f53\u4f60\u6307\u5b9a\u4e00\u4e2a\u503c\u65f6\uff0cNumber \u5bf9\u8c61\u5c31\u4f1a\u88ab\u521b\u5efa\uff1a<\/p>\n

var1 = 1\r\nvar2 = 10<\/pre>\n

\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528del\u8bed\u53e5\u5220\u9664\u4e00\u4e9b\u5bf9\u8c61\u5f15\u7528\u3002<\/p>\n

del\u8bed\u53e5\u7684\u8bed\u6cd5\u662f\uff1a<\/p>\n

del var1[,var2[,var3[....,varN]]]<\/pre>\n

\u60a8\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528del\u8bed\u53e5\u5220\u9664\u5355\u4e2a\u6216\u591a\u4e2a\u5bf9\u8c61\u3002\u4f8b\u5982\uff1a<\/p>\n

del var\r\ndel var_a, var_b<\/pre>\n

\u6570\u503c\u8fd0\u7b97<\/p>\n

\u5b9e\u4f8b\r\n>>>5 + 4  # \u52a0\u6cd5\r\n9\r\n>>> 4.3 - 2 # \u51cf\u6cd5\r\n2.3\r\n>>> 3 * 7  # \u4e58\u6cd5\r\n21\r\n>>> 2 \/ 4  # \u9664\u6cd5\uff0c\u5f97\u5230\u4e00\u4e2a\u6d6e\u70b9\u6570\r\n0.5\r\n>>> 2 \/\/ 4 # \u9664\u6cd5\uff0c\u5f97\u5230\u4e00\u4e2a\u6574\u6570\r\n0\r\n>>> 17 % 3 # \u53d6\u4f59 \r\n2\r\n>>> 2 ** 5 # \u4e58\u65b9\r\n32<\/pre>\n

\u6ce8\u610f\uff1a<\/strong><\/p>\n

1\u3001Python\u53ef\u4ee5\u540c\u65f6\u4e3a\u591a\u4e2a\u53d8\u91cf\u8d4b\u503c\uff0c\u5982a, b = 1, 2\u3002
\n2\u3001\u4e00\u4e2a\u53d8\u91cf\u53ef\u4ee5\u901a\u8fc7\u8d4b\u503c\u6307\u5411\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u3002
\n3\u3001\u6570\u503c\u7684\u9664\u6cd5\u5305\u542b\u4e24\u4e2a\u8fd0\u7b97\u7b26\uff1a\/ \u8fd4\u56de\u4e00\u4e2a\u6d6e\u70b9\u6570\uff0c\/\/ \u8fd4\u56de\u4e00\u4e2a\u6574\u6570\u3002
\n4\u3001\u5728\u6df7\u5408\u8ba1\u7b97\u65f6\uff0cPython\u4f1a\u628a\u6574\u578b\u8f6c\u6362\u6210\u4e3a\u6d6e\u70b9\u6570\u3002<\/p>\n

\u6570\u503c\u7c7b\u578b\u5b9e\u4f8b<\/strong><\/p>\n\n\n\n\n\n\n\n\n\n\n
int<\/th>\nfloat<\/th>\ncomplex<\/th>\n<\/tr>\n
10<\/td>\n0.0<\/td>\n3.14j<\/td>\n<\/tr>\n
100<\/td>\n15.20<\/td>\n45.j<\/td>\n<\/tr>\n
-786<\/td>\n-21.9<\/td>\n9.322e-36j<\/td>\n<\/tr>\n
080<\/td>\n32.3e+18<\/td>\n.876j<\/td>\n<\/tr>\n
-0490<\/td>\n-90.<\/td>\n-.6545+0J<\/td>\n<\/tr>\n
-0x260<\/td>\n-32.54e100<\/td>\n3e+26J<\/td>\n<\/tr>\n
0x69<\/td>\n70.2E-12<\/td>\n4.53e-7j<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"

Python3 \u652f\u6301 int\u3001float\u3001bool\u3001complex\uff08\u590d\u6570\uff09\u3002 \u5728Python 3\u91cc\uff0c\u53ea\u6709\u4e00\u79cd\u6574 […]<\/p>\n","protected":false},"author":1470,"featured_media":162524,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-162522","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162522","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1470"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=162522"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162522\/revisions"}],"predecessor-version":[{"id":162526,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162522\/revisions\/162526"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/162524"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=162522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=162522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=162522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}