{"id":172693,"date":"2023-07-29T22:54:06","date_gmt":"2023-07-29T14:54:06","guid":{"rendered":"http:\/\/www.idc.net\/help\/172693\/"},"modified":"2023-07-29T22:54:06","modified_gmt":"2023-07-29T14:54:06","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9abool%e5%9c%a8python%e4%b8%ad%e5%a6%82%e4%bd%95%e5%bc%95%e7%94%a8%e5%af%b9%e8%b1%a1%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/172693\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1abool\u5728python\u4e2d\u5982\u4f55\u5f15\u7528\u5bf9\u8c61\uff1f"},"content":{"rendered":"<p style=\"text-align:center\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 16px\"><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/image\/413\/535\/159\/1607253694517534.png\" class=\"aligncenter\"><\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 16px\">\u5f53\u6211\u4eec\u60f3\u8981\u8fdb\u884c\u903b\u8f91\u5224\u65ad\u65f6\uff0c\u6839\u636e\u4e0d\u540c\u7684\u7ed9\u5b9a\u6761\u4ef6\uff0c\u4f1a\u8f93\u51fa\u4e00\u4e2a\u771f\u6216\u8005\u662f\u5047\u7684\u7ed3\u679c\u3002\u6211\u4eec\u4eca\u5929\u6240\u8981\u8bb2\u7684bool\u501f\u7528\u6570\u5b66\u4e2d\u7684\u903b\u8f91\u5224\u65ad\u601d\u60f3\uff0c\u5c31\u5f88\u597d\u7406\u89e3\u5b83\u7684\u4f7f\u7528\u4e86\u3002\u56e0\u4e3abool\u7684\u503c\u5c31\u662f\u771f\u6216\u8005\u5047\uff0c\u5728\u7ed3\u679c\u8f93\u51fa\u4e0a\u4e5f\u53ea\u4f1a\u51fa\u73b0\u4e00\u4e2a\u3002\u4e0b\u9762\u6839\u636ebool\u7684\u4f7f\u7528\uff0c\u4e3a\u5927\u5bb6\u8fdb\u884c\u5f15\u7528\u5bf9\u8c61\u7684\u65b9\u6cd5\u4ecb\u7ecd\u3002<\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u5e03\u5c14\u578b\u5bf9\u8c61\u53ea\u6709\u4e24\u4e2a\u503c\uff0c<\/span>True\u548cFalse\uff0c\u5b83\u4eec\u4f1a\u653e\u5728\u7f13\u51b2\u6c60\u5171\u4eab\u533a\uff0c\u65e0\u8bba\u6709\u591a\u5c11\u6b21\u5f15\u7528\uff0c\u53ea\u4f1a\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u3002<\/span><\/p>\n<pre>c&nbsp;=&nbsp;True&nbsp;#\u53d8\u91cfc\u6307\u5411\u4e86\u6d6e\u70b9\u578b\u5bf9\u8c61\uff0c\u503c\u4e3a1.5\nprint(\"c&nbsp;=&nbsp;{},&nbsp;c\u7684\u5730\u5740:{},&nbsp;c\u7684\u7c7b\u578b\u4e3a:{}\".format(c,&nbsp;id(c),type(c)))\nd&nbsp;=&nbsp;True&nbsp;#\u6d6e\u70b9\u578b\u5bf9\u8c61\u6ca1\u6709\u5171\u4eab\u7f13\u51b2\u533a\uff0c\u4f1a\u65b0\u5efa\u4e00\u4e2a\u5bf9\u8c61\nprint(\"d&nbsp;=&nbsp;{},&nbsp;d\u7684\u5730\u5740:{},&nbsp;d\u7684\u7c7b\u578b\u4e3a:{}\".format(d,&nbsp;id(d),type(d)))\nprint(\"c\u548cd\u662f\u5426\u4e3a\u540c\u4e00\u5bf9\u8c61\uff1a{}\".format(c&nbsp;is&nbsp;d))&nbsp;&nbsp;#c\u548cd\u6307\u5411\u4e86\u76f8\u540c\u5bf9\u8c61\nprint(id(c&nbsp;is&nbsp;d))<\/pre>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/span><\/p>\n<pre>c&nbsp;=&nbsp;True,&nbsp;c\u7684\u5730\u5740:4527372208,&nbsp;c\u7684\u7c7b\u578b\u4e3a:&lt;class&nbsp;'bool'&gt;\nd&nbsp;=&nbsp;True,&nbsp;d\u7684\u5730\u5740:4527372208,&nbsp;d\u7684\u7c7b\u578b\u4e3a:&lt;class&nbsp;'bool'&gt;\nc\u548cd\u662f\u5426\u4e3a\u540c\u4e00\u5bf9\u8c61\uff1aTrue\n4527372208<\/pre>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u6240\u6709\u7684<\/span>True\u90fd\u662f\u5f15\u7528\u540c\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u4eec\u7684\u5730\u5740\u90fd\u662f&amp;4527372208\u3002\u540c\u7406\uff0cFalse\u4e5f\u662f\u4e00\u6837\u3002<\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u5728<\/span> 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<\/span><\/p>\n<pre>&gt;&gt;&gt;&nbsp;True&nbsp;+&nbsp;True\n2\n&gt;&gt;&gt;&nbsp;True&nbsp;-&nbsp;False\n1\n&gt;&gt;&gt;&nbsp;True&nbsp;*&nbsp;False\n0\n&gt;&gt;&gt;&nbsp;True&nbsp;\/&nbsp;False\nTraceback&nbsp;(most&nbsp;recent&nbsp;call&nbsp;last):\n&nbsp;&nbsp;File&nbsp;\"&lt;stdin&gt;\",&nbsp;line&nbsp;1,&nbsp;in&nbsp;&lt;module&gt;\nZeroDivisionError:&nbsp;int&nbsp;division&nbsp;or&nbsp;modulo&nbsp;by&nbsp;zero<\/pre>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1;font-size: 14px\">\u5728\u67d0\u4e9b\u5730\u65b9\uff08\u5982<\/span> if \u8bed\u53e5\uff09\uff0cPython \u6240\u9884\u671f\u7684\u5c31\u662f\u4e00\u4e2a\u53ef\u8ba1\u7b97\u51fa\u5e03\u5c14\u7c7b\u578b\u503c\u7684\u8868\u8fbe\u5f0f\u3002\u8fd9\u4e9b\u5730\u65b9\u79f0\u4e3a\u5e03\u5c14\u7c7b\u578b\u4e0a\u4e0b\u6587\u73af\u5883\u3002\u4e8b\u5b9e\u4e0a\uff0c\u53ef\u5728\u5e03\u5c14\u7c7b\u578b\u4e0a\u4e0b\u6587\u73af\u5883\u4e2d\u4f7f\u7528\u4efb\u4f55\u8868\u8fbe\u5f0f\uff0cPython \u90fd\u5c06\u8bd5\u56fe\u5224\u65ad\u5176\u771f\u503c\u3002<\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 14px\">&nbsp;<\/span><\/p>\n<p style=\"line-height: 1.75em\"><span style=\"font-family: \u5fae\u8f6f\u96c5\u9ed1,Microsoft YaHei;font-size: 16px\">bool\u5728python\u4e2d\u5f15\u7528\u5bf9\u8c61\u7684\u65b9\u6cd5\u5230\u8fd9\u91cc\u5c31\u5168\u90e8\u5206\u4eab\u7ed9\u5927\u5bb6\u4e86\uff0c\u66f4\u591a\u7684\u4f7f\u7528\u5c0f\u4f19\u4f34\u4eec\u53ef\u4ee5\u5728\u8bfe\u540e\u81ea\u884c\u6316\u6398\u4e00\u4e0b\uff0c\u56e0\u4e3a\u7bc7\u5e45\u7684\u539f\u56e0\u8fd9\u91cc\u5c0f\u7f16\u5c31\u4e0d\u518d\u53d9\u8ff0\u4e86\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u6211\u4eec\u60f3\u8981\u8fdb\u884c\u903b\u8f91\u5224\u65ad\u65f6\uff0c\u6839\u636e\u4e0d\u540c\u7684\u7ed9\u5b9a\u6761\u4ef6\uff0c\u4f1a\u8f93\u51fa\u4e00\u4e2a\u771f\u6216\u8005\u662f\u5047\u7684\u7ed3\u679c\u3002\u6211\u4eec\u4eca\u5929\u6240\u8981\u8bb2\u7684bool\u501f\u7528\u6570\u5b66\u4e2d\u7684 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":172694,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-172693","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/172693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=172693"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/172693\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/172694"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=172693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=172693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=172693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}