{"id":38313,"date":"2025-05-20T09:17:52","date_gmt":"2025-05-20T01:17:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/38313.html"},"modified":"2025-05-20T09:17:52","modified_gmt":"2025-05-20T01:17:52","slug":"%e7%ac%a6%e5%90%88python%e9%a3%8e%e6%a0%bc%e7%9a%84%e5%af%b9%e8%b1%a1%e5%86%8d%e8%b0%88%e5%90%91%e9%87%8f%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/38313.html","title":{"rendered":"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b)"},"content":{"rendered":"<h2>\u518d\u8c08\u5411\u91cf\u7c7b<\/h2>\n<p>\u4e3a\u4e86\u8bf4\u660e\u7528\u4e8e\u751f\u6210\u5bf9\u8c61\u8868\u793a\u5f62\u5f0f\u7684\u4f17\u591a\u65b9\u6cd5&#xff0c;\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a Vector2d \u7c7b&#xff0c;\u5b83\u4e0e\u7b2c 1 \u7ae0\u4e2d\u7684\u7c7b\u4f3c\u3002\u8fd9\u4e00\u8282\u548c\u63a5\u4e0b\u6765\u7684\u51e0\u8282\u4f1a\u4e0d\u65ad\u5b9e \u73b0\u8fd9\u4e2a\u7c7b\u3002\u6211\u4eec\u671f\u671b Vector2d \u5b9e\u4f8b\u5177\u6709\u7684\u57fa\u672c\u884c\u4e3a\u5982\u793a\u4f8b 9-1 \u6240\u793a\u3002<\/p>\n<p>\u793a\u4f8b 9-1\u3000Vector2d \u5b9e\u4f8b\u6709\u591a\u79cd\u8868\u793a\u5f62\u5f0f<\/p>\n<p><span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> v1 <span class=\"token operator\">&#061;<\/span> Vector2d<span class=\"token punctuation\">(<\/span><span class=\"token number\">3<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>v1<span class=\"token punctuation\">.<\/span>x<span class=\"token punctuation\">,<\/span> v1<span class=\"token punctuation\">.<\/span>y<span class=\"token punctuation\">)<\/span> \u278a<br \/>\n<span class=\"token number\">3.0<\/span> <span class=\"token number\">4.0<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> x<span class=\"token punctuation\">,<\/span> y <span class=\"token operator\">&#061;<\/span> v1 \u278b<br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> x<span class=\"token punctuation\">,<\/span> y<br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token number\">3.0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4.0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> v1 \u278c<br \/>\nVector2d<span class=\"token punctuation\">(<\/span><span class=\"token number\">3.0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4.0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> v1_clone <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">eval<\/span><span class=\"token punctuation\">(<\/span><span class=\"token builtin\">repr<\/span><span class=\"token punctuation\">(<\/span>v1<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> \u278d<br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> v1 <span class=\"token operator\">&#061;&#061;<\/span> v1_clone \u278e<br \/>\n<span class=\"token boolean\">True<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>v1<span class=\"token punctuation\">)<\/span> \u278f<br \/>\n<span class=\"token punctuation\">(<\/span><span class=\"token number\">3.0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">4.0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> octets <span class=\"token operator\">&#061;<\/span> <span class=\"token builtin\">bytes<\/span><span class=\"token punctuation\">(<\/span>v1<span class=\"token punctuation\">)<\/span> \u2790<br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> octets<br \/>\n<span class=\"token string\">b&#039;d\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x08&#064;\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x00\\\\\\\\x10&#064;&#039;<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">abs<\/span><span class=\"token punctuation\">(<\/span>v1<span class=\"token punctuation\">)<\/span> \u2791<br \/>\n<span class=\"token number\">5.0<\/span><br \/>\n<span class=\"token operator\">&gt;&gt;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">(<\/span>v1<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">bool<\/span><span class=\"token punctuation\">(<\/span>Vector2d<span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> \u2792<\/p>\n<p>\u2776 Vector2d \u5b9e\u4f8b\u7684\u5206\u91cf\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u5c5e\u6027\u8bbf\u95ee&#xff08;\u65e0\u9700\u8c03\u7528\u8bfb\u503c\u65b9 \u6cd5&#xff09;\u3002 \u2777 Vector2d \u5b9e\u4f8b\u53ef\u4ee5\u62c6\u5305\u6210\u53d8\u91cf\u5143\u7ec4\u3002 \u2778 repr \u51fd\u6570\u8c03\u7528 Vector2d \u5b9e\u4f8b&#xff0c;\u5f97\u5230\u7684\u7ed3\u679c\u7c7b\u4f3c\u4e8e\u6784\u5efa\u5b9e\u4f8b\u7684\u6e90 \u7801\u3002 \u2779 \u8fd9\u91cc\u4f7f\u7528 eval \u51fd\u6570&#xff0c;\u8868\u660e repr \u51fd\u6570\u8c03\u7528 Vector2d \u5b9e\u4f8b\u5f97\u5230\u7684\u662f \u5bf9\u6784\u9020\u65b9\u6cd5\u7684\u51c6\u786e\u8868\u8ff0\u3002<\/p>\n<p>\u277a Vector2d \u5b9e\u4f8b\u652f\u6301\u4f7f\u7528 &#061;&#061; \u6bd4\u8f83&#xff1b;\u8fd9\u6837\u4fbf\u4e8e\u6d4b\u8bd5\u3002 \u277b print \u51fd\u6570\u4f1a\u8c03\u7528 str \u51fd\u6570&#xff0c;\u5bf9 Vector2d \u6765\u8bf4&#xff0c;\u8f93\u51fa\u7684\u662f\u4e00\u4e2a\u6709 \u5e8f\u5bf9\u3002 \u277c bytes \u51fd\u6570\u4f1a\u8c03\u7528__bytes__ \u65b9\u6cd5&#xff0c;\u751f\u6210\u5b9e\u4f8b\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u3002 \u277d abs \u51fd\u6570\u4f1a\u8c03\u7528__abs__ \u65b9\u6cd5&#xff0c;\u8fd4\u56de Vector2d \u5b9e\u4f8b\u7684\u6a21\u3002 \u277e bool \u51fd\u6570\u4f1a\u8c03\u7528__bool__ \u65b9\u6cd5&#xff0c;\u5982\u679c Vector2d \u5b9e\u4f8b\u7684\u6a21\u4e3a\u96f6&#xff0c; \u8fd4\u56de False&#xff0c;\u5426\u5219\u8fd4\u56de True\u3002<\/p>\n<p>\u793a\u4f8b 9-1 \u4e2d\u7684 Vector2d \u7c7b\u5728 vector2d_v0.py \u6587\u4ef6\u4e2d\u5b9e\u73b0&#xff08;\u89c1\u793a\u4f8b 9- 2&#xff09;\u3002\u8fd9\u6bb5\u4ee3\u7801\u57fa\u4e8e\u793a\u4f8b 1-2&#xff0c;\u9664\u4e86 &#061;&#061; \u4e4b\u5916&#xff08;\u5728\u6d4b\u8bd5\u4e2d\u7528\u5f97\u5230&#xff09;&#xff0c;\u5176\u4ed6 \u4e2d\u7f00\u8fd0\u7b97\u7b26\u5c06\u5728\u7b2c 13 \u7ae0\u5b9e\u73b0\u3002\u73b0\u5728&#xff0c;Vector2d \u7528\u5230\u4e86\u51e0\u4e2a\u7279\u6b8a\u65b9\u6cd5&#xff0c; \u8fd9\u4e9b\u65b9\u6cd5\u63d0\u4f9b\u7684\u64cd\u4f5c\u662f Python \u9ad8\u624b\u671f\u5f85\u8bbe\u8ba1\u826f\u597d\u7684\u5bf9\u8c61\u6240\u63d0\u4f9b\u7684\u3002<\/p>\n<p>\u793a\u4f8b 9-2\u3000vector2d_v0.py&#xff1a;\u76ee\u524d\u5b9a\u4e49\u7684\u90fd\u662f\u7279\u6b8a\u65b9\u6cd5<\/p>\n<p>from array import array<br \/>\nimport math<br \/>\n  class Vector2d:<br \/>\n    typecode &#061; &#039;d&#039; \u278a<br \/>\n    def __init__(self, x, y):<br \/>\n      self.x &#061; float(x) \u278b<br \/>\n      self.y &#061; float(y)<br \/>\n    def __iter__(self):<br \/>\n      return (i for i in (self.x, self.y)) \u278c<br \/>\n    def __repr__(self):<br \/>\nclass_name &#061; type(self).__name__<br \/>\n  return &#039;{}({!r}, {!r})&#039;.format(class_name, *self) \u278d<br \/>\n  def __str__(self):<br \/>\n    return str(tuple(self)) \u278e<br \/>\n  def __bytes__(self):<br \/>\n    return (bytes([ord(self.typecode)]) &#043; \u278f<br \/>\nbytes(array(self.typecode, self))) \u2790<br \/>\n  def __eq__(self, other):<br \/>\n    return tuple(self) &#061;&#061; tuple(other) \u2791<br \/>\n  def __abs__(self):<br \/>\n    return math.hypot(self.x, self.y) \u2792<br \/>\n  def __bool__(self):<br \/>\n    return bool(abs(self)) \u2793<\/p>\n<p>\u2776 typecode \u662f\u7c7b\u5c5e\u6027&#xff0c;\u5728 Vector2d \u5b9e\u4f8b\u548c\u5b57\u8282\u5e8f\u5217\u4e4b\u95f4\u8f6c\u6362\u65f6\u4f7f \u7528\u3002 \u2777 \u5728__init__ \u65b9\u6cd5\u4e2d\u628a x \u548c y \u8f6c\u6362\u6210\u6d6e\u70b9\u6570&#xff0c;\u5c3d\u65e9\u6355\u83b7\u9519\u8bef&#xff0c;\u4ee5\u9632 \u8c03\u7528 Vector2d \u51fd\u6570\u65f6\u4f20\u5165\u4e0d\u5f53\u53c2\u6570\u3002 \u2778 \u5b9a\u4e49__iter__ \u65b9\u6cd5&#xff0c;\u628a Vector2d \u5b9e\u4f8b\u53d8\u6210\u53ef\u8fed\u4ee3\u7684\u5bf9\u8c61&#xff0c;\u8fd9\u6837\u624d \u80fd\u62c6\u5305&#xff08;\u4f8b\u5982&#xff0c;x, y &#061; my_vector&#xff09;\u3002\u8fd9\u4e2a\u65b9\u6cd5\u7684\u5b9e\u73b0\u65b9\u5f0f\u5f88\u7b80\u5355&#xff0c; \u76f4\u63a5\u8c03\u7528\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u4e00\u4e2a\u63a5\u4e00\u4e2a\u4ea7\u51fa\u5206\u91cf\u3002 \u8fd9\u4e00\u884c\u4e5f\u53ef\u4ee5\u5199\u6210 yield self.x; yield.self.y\u3002\u7b2c 14 \u7ae0\u4f1a\u8fdb\u4e00\u6b65\u8ba8\u8bba__iter__ \u7279\u6b8a\u65b9 \u6cd5\u3001\u751f\u6210\u5668\u8868\u8fbe\u5f0f\u548c yield \u5173\u952e\u5b57\u3002 \u2779__repr__ \u65b9\u6cd5\u4f7f\u7528 {!r} \u83b7\u53d6\u5404\u4e2a\u5206\u91cf\u7684\u8868\u793a\u5f62\u5f0f&#xff0c;\u7136\u540e\u63d2\u503c&#xff0c;\u6784 \u6210\u4e00\u4e2a\u5b57\u7b26\u4e32&#xff1b;\u56e0\u4e3a Vector2d \u5b9e\u4f8b\u662f\u53ef\u8fed\u4ee3\u7684\u5bf9\u8c61&#xff0c;\u6240\u4ee5 *self \u4f1a\u628a x \u548c y \u5206\u91cf\u63d0\u4f9b\u7ed9 format \u51fd\u6570\u3002 \u277a \u4ece\u53ef\u8fed\u4ee3\u7684 Vector2d \u5b9e\u4f8b\u4e2d\u53ef\u4ee5\u8f7b\u677e\u5730\u5f97\u5230\u4e00\u4e2a\u5143\u7ec4&#xff0c;\u663e\u793a\u4e3a\u4e00\u4e2a \u6709\u5e8f\u5bf9\u3002 \u277b \u4e3a\u4e86\u751f\u6210\u5b57\u8282\u5e8f\u5217&#xff0c;\u6211\u4eec\u628a typecode \u8f6c\u6362\u6210\u5b57\u8282\u5e8f\u5217&#xff0c;\u7136\u540e\u2026\u2026 \u277c \u2026\u2026\u8fed\u4ee3 Vector2d \u5b9e\u4f8b&#xff0c;\u5f97\u5230\u4e00\u4e2a\u6570\u7ec4&#xff0c;\u518d\u628a\u6570\u7ec4\u8f6c\u6362\u6210\u5b57\u8282\u5e8f \u5217\u3002 \u277d \u4e3a\u4e86\u5feb\u901f\u6bd4\u8f83\u6240\u6709\u5206\u91cf&#xff0c;\u5728\u64cd\u4f5c\u6570\u4e2d\u6784\u5efa\u5143\u7ec4\u3002\u5bf9 Vector2d \u5b9e\u4f8b\u6765 \u8bf4&#xff0c;\u53ef\u4ee5\u8fd9\u6837\u505a&#xff0c;\u4e0d\u8fc7\u4ecd\u6709\u95ee\u9898\u3002\u53c2\u89c1\u4e0b\u9762\u7684\u8b66\u544a\u3002 \u277e \u6a21\u662f x \u548c y \u5206\u91cf\u6784\u6210\u7684\u76f4\u89d2\u4e09\u89d2\u5f62\u7684\u659c\u8fb9\u957f\u3002 \u277f__bool__ \u65b9\u6cd5\u4f7f\u7528 abs(self) \u8ba1\u7b97\u6a21&#xff0c;\u7136\u540e\u628a\u7ed3\u679c\u8f6c\u6362\u6210\u5e03\u5c14 \u503c&#xff0c;\u56e0\u6b64&#xff0c;0.0 \u662f False&#xff0c;\u975e\u96f6\u503c\u662f True\u3002<\/p>\n<p>\u793a\u4f8b 9-2 \u4e2d\u7684__eq__ \u65b9\u6cd5&#xff0c;\u5728\u4e24\u4e2a\u64cd\u4f5c\u6570\u90fd\u662f Vector2d \u5b9e\u4f8b\u65f6\u53ef\u7528&#xff0c;\u4e0d\u8fc7\u62ff Vector2d \u5b9e\u4f8b\u4e0e\u5176\u4ed6\u5177\u6709\u76f8\u540c\u6570\u503c\u7684\u53ef\u8fed\u4ee3 \u5bf9\u8c61\u76f8\u6bd4&#xff0c;\u7ed3\u679c\u4e5f\u662f True&#xff08;\u5982 Vector(3, 4) &#061;&#061; [3, 4]&#xff09;\u3002\u8fd9 \u4e2a\u884c\u4e3a\u53ef\u4ee5\u89c6\u4f5c\u7279\u6027&#xff0c;\u4e5f\u53ef\u4ee5\u89c6\u4f5c\u7f3a\u9677\u3002\u7b2c 13 \u7ae0\u8bb2\u5230\u8fd0\u7b97\u7b26\u91cd\u8f7d \u65f6\u624d\u80fd\u8fdb\u4e00\u6b65\u8ba8\u8bba\u3002<\/p>\n<p>\u6211\u4eec\u5df2\u7ecf\u5b9a\u4e49\u4e86\u5f88\u591a\u57fa\u672c\u65b9\u6cd5&#xff0c;\u4f46\u662f\u663e\u7136\u5c11\u4e86\u4e00\u4e2a\u64cd\u4f5c&#xff1a;\u4f7f\u7528 bytes() \u51fd\u6570\u751f\u6210\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u91cd\u5efa Vector2d \u5b9e\u4f8b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb720\u6b21\uff0c\u70b9\u8d5e5\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u277e bool \u51fd\u6570\u4f1a\u8c03\u7528__bool__ \u65b9\u6cd5\uff0c\u5982\u679c Vector2d \u5b9e\u4f8b\u7684\u6a21\u4e3a\u96f6\uff0c\u277b print \u51fd\u6570\u4f1a\u8c03\u7528 str \u51fd\u6570\uff0c\u5bf9 Vector2d \u6765\u8bf4\uff0c\u8f93\u51fa\u7684\u662f\u4e00\u4e2a\u6709\u3002\u2778 \u5b9a\u4e49__iter__ \u65b9\u6cd5\uff0c\u628a Vector2d \u5b9e\u4f8b\u53d8\u6210\u53ef\u8fed\u4ee3\u7684\u5bf9\u8c61\uff0c\u8fd9\u6837\u624d\u3002\u277c bytes \u51fd\u6570\u4f1a\u8c03\u7528__bytes__ \u65b9\u6cd5\uff0c\u751f\u6210\u5b9e\u4f8b\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u3002\u277d abs \u51fd\u6570\u4f1a\u8c03\u7528__abs__ \u65b9\u6cd5\uff0c\u8fd4\u56de Vector2d \u5b9e\u4f8b\u7684\u6a21\u3002\u2777 \u5728__init__ \u65b9\u6cd5\u4e2d\u628a x \u548c y \u8f6c\u6362\u6210\u6d6e\u70b9\u6570\uff0c\u5c3d\u65e9\u6355\u83b7\u9519\u8bef\uff0c\u4ee5\u9632\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,190,207,3347],"topic":[],"class_list":["post-38313","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-190","tag-207"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/38313.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb720\u6b21\uff0c\u70b9\u8d5e5\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u277e bool \u51fd\u6570\u4f1a\u8c03\u7528__bool__ \u65b9\u6cd5\uff0c\u5982\u679c Vector2d \u5b9e\u4f8b\u7684\u6a21\u4e3a\u96f6\uff0c\u277b print \u51fd\u6570\u4f1a\u8c03\u7528 str \u51fd\u6570\uff0c\u5bf9 Vector2d \u6765\u8bf4\uff0c\u8f93\u51fa\u7684\u662f\u4e00\u4e2a\u6709\u3002\u2778 \u5b9a\u4e49__iter__ \u65b9\u6cd5\uff0c\u628a Vector2d \u5b9e\u4f8b\u53d8\u6210\u53ef\u8fed\u4ee3\u7684\u5bf9\u8c61\uff0c\u8fd9\u6837\u624d\u3002\u277c bytes \u51fd\u6570\u4f1a\u8c03\u7528__bytes__ \u65b9\u6cd5\uff0c\u751f\u6210\u5b9e\u4f8b\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u3002\u277d abs \u51fd\u6570\u4f1a\u8c03\u7528__abs__ \u65b9\u6cd5\uff0c\u8fd4\u56de Vector2d \u5b9e\u4f8b\u7684\u6a21\u3002\u2777 \u5728__init__ \u65b9\u6cd5\u4e2d\u628a x \u548c y \u8f6c\u6362\u6210\u6d6e\u70b9\u6570\uff0c\u5c3d\u65e9\u6355\u83b7\u9519\u8bef\uff0c\u4ee5\u9632\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/38313.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-20T01:17:52+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38313.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/38313.html\",\"name\":\"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-20T01:17:52+00:00\",\"dateModified\":\"2025-05-20T01:17:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/38313.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/38313.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/38313.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/38313.html","og_locale":"zh_CN","og_type":"article","og_title":"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb720\u6b21\uff0c\u70b9\u8d5e5\u6b21\uff0c\u6536\u85cf4\u6b21\u3002\u277e bool \u51fd\u6570\u4f1a\u8c03\u7528__bool__ \u65b9\u6cd5\uff0c\u5982\u679c Vector2d \u5b9e\u4f8b\u7684\u6a21\u4e3a\u96f6\uff0c\u277b print \u51fd\u6570\u4f1a\u8c03\u7528 str \u51fd\u6570\uff0c\u5bf9 Vector2d \u6765\u8bf4\uff0c\u8f93\u51fa\u7684\u662f\u4e00\u4e2a\u6709\u3002\u2778 \u5b9a\u4e49__iter__ \u65b9\u6cd5\uff0c\u628a Vector2d \u5b9e\u4f8b\u53d8\u6210\u53ef\u8fed\u4ee3\u7684\u5bf9\u8c61\uff0c\u8fd9\u6837\u624d\u3002\u277c bytes \u51fd\u6570\u4f1a\u8c03\u7528__bytes__ \u65b9\u6cd5\uff0c\u751f\u6210\u5b9e\u4f8b\u7684\u4e8c\u8fdb\u5236\u8868\u793a\u5f62\u5f0f\u3002\u277d abs \u51fd\u6570\u4f1a\u8c03\u7528__abs__ \u65b9\u6cd5\uff0c\u8fd4\u56de Vector2d \u5b9e\u4f8b\u7684\u6a21\u3002\u2777 \u5728__init__ \u65b9\u6cd5\u4e2d\u628a x \u548c y \u8f6c\u6362\u6210\u6d6e\u70b9\u6570\uff0c\u5c3d\u65e9\u6355\u83b7\u9519\u8bef\uff0c\u4ee5\u9632\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/38313.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-20T01:17:52+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/38313.html","url":"https:\/\/www.wsisp.com\/helps\/38313.html","name":"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b) - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-20T01:17:52+00:00","dateModified":"2025-05-20T01:17:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/38313.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/38313.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/38313.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u7b26\u5408Python\u98ce\u683c\u7684\u5bf9\u8c61(\u518d\u8c08\u5411\u91cf\u7c7b)"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=38313"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/38313\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=38313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=38313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=38313"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=38313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}