{"id":47801,"date":"2025-07-30T09:22:32","date_gmt":"2025-07-30T01:22:32","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/47801.html"},"modified":"2025-07-30T09:22:32","modified_gmt":"2025-07-30T01:22:32","slug":"python%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e7%9a%84%e5%86%99%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/47801.html","title":{"rendered":"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5"},"content":{"rendered":"<h3>Python\u9762\u5411\u5bf9\u8c61<\/h3>\n<hr \/>\n<hr \/>\n<h4>\u521b\u5efa\u7c7b<\/h4>\n<p>\u4f7f\u7528class\u8bed\u53e5\u6765\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u7c7b&#xff0c;class\u4e4b\u540e\u4e3a\u7c7b\u7684\u540d\u5b57\u5e76\u4e14\u4ee5\u5192\u53f7\u7ed3\u675f<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">ClassName<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token string\">&#039;\u7c7b\u7684\u5e2e\u52a9\u4fe1\u606f&#039;<\/span> <span class=\"token comment\"># \u7c7b\u6587\u6863\u5e2e\u52a9\u5b57\u7b26\u4e32<\/span><br \/>\n    class_suite <span class=\"token comment\"># \u7c7b\u4f53<\/span><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5b9e\u4f8b<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Employee<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u6240\u6709\u7684\u5458\u5de5\u7684\u57fa\u7c7b&#034;&#034;&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u6784\u9020\u5668<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> name<span class=\"token punctuation\">,<\/span> age<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6784\u9020\u51fd\u6570\u88ab\u8c03\u7528&#xff01;&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>name <span class=\"token operator\">&#061;<\/span> name<br \/>\n        self<span class=\"token punctuation\">.<\/span>age <span class=\"token operator\">&#061;<\/span> age<br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5c5e\u6027<\/span><br \/>\n    name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;&#034;<\/span><br \/>\n    age <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><\/p>\n<p>    <span class=\"token comment\"># \u65b9\u6cd5<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">show<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u53eb%s,\u6211\u4eca\u5e74%d&#034;<\/span> <span class=\"token operator\">%<\/span> <span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>age<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__del__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6790\u6784\u51fd\u6570\u88ab\u8c03\u7528&#xff01;&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    xiaoming <span class=\"token operator\">&#061;<\/span> Employee<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5c0f\u7c73&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">21<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    xiaoming<span class=\"token punctuation\">.<\/span>show<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">pass<\/span><\/p>\n<p><span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;__main__&#034;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    main<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5728\u8be5\u5b9e\u4f8b\u4e2d\u51fa\u73b0\u4e86\u4e24\u4e2a\u7279\u6b8a\u51fd\u6570&#xff1a;<\/p>\n<ul>\n<li>def __init__(): \u6784\u9020\u5668&#xff0c;\u7528\u4e8e\u521d\u59cb\u5316\u5bf9\u8c61<\/li>\n<li>def __del__(): \u6790\u6784\u5668&#xff0c;\u5728\u9500\u6bc1\u5bf9\u8c61\u4e4b\u524d\u8c03\u7528<\/li>\n<\/ul>\n<p>self\u53c2\u6570&#xff1a;<\/p>\n<ul>\n<li>\u5728python\u7684\u9762\u5411\u5bf9\u8c61\u65b9\u6cd5\u4e2d&#xff0c;\u7b2c\u4e00\u4e2a\u53c2\u6570\u6c38\u8fdc\u662fself&#xff0c;\u6307\u5411\u8be5\u5bf9\u8c61\u81ea\u5df1\u672c\u8eab&#xff0c;\u7c7b\u4f3c\u4e0eC&#043;&#043;\u4e2d\u7684this\u6307\u9488<\/li>\n<li>self\u4ee3\u8868\u7c7b\u7684\u5b9e\u4f8b&#xff0c;\u800c\u975e\u7c7b\u672c\u8eab<\/li>\n<li>\u5982\u679c\u8981\u8ba9self\u6307\u5411\u7c7b\u672c\u8eab&#xff0c;\u5219\u9700\u8981\u5199&#xff1a;self.__class__<\/li>\n<li>self\u4e0d\u662f\u5173\u952e\u5b57&#xff0c;\u53ef\u4ee5\u968f\u4fbf\u6362\u6210\u5176\u4ed6\u7684\u5b57&#xff0c;\u7167\u6837\u6267\u884c<\/li>\n<\/ul>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>this<span class=\"token punctuation\">,<\/span> name<span class=\"token punctuation\">,<\/span> age<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6784\u9020\u51fd\u6570\u88ab\u8c03\u7528&#xff01;&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>this<span class=\"token punctuation\">.<\/span>__class__<span class=\"token punctuation\">)<\/span><br \/>\n        this<span class=\"token punctuation\">.<\/span>name <span class=\"token operator\">&#061;<\/span> name<br \/>\n        this<span class=\"token punctuation\">.<\/span>age <span class=\"token operator\">&#061;<\/span> age<br \/>\n        <span class=\"token keyword\">pass<\/span><\/p>\n<hr \/>\n<h4>\u7c7b\u7684\u5b9e\u4f8b\u5316<\/h4>\n<p>Python\u7684\u5b9e\u4f8b\u5316\u4e2d\u6ca1\u6709new\u5173\u952e\u5b57&#xff0c;\u800c\u662f\u7c7b\u4f3c\u4e8e\u51fd\u6570\u7684\u8c03\u7528<br \/>\n\u4ee5\u4e0b\u5b9e\u4f8b\u5316\u65b9\u6cd5\u4e2d\u4f7f\u7528Employee\u6765\u5b9e\u4f8b\u5316&#xff0c;\u5e76\u4e14\u901a\u8fc7__init__\u65b9\u6cd5\u6765\u63a5\u6536\u53c2\u6570<\/p>\n<p><span class=\"token triple-quoted-string string\">&#039;&#039;&#039;\u521b\u5efaEmployee\u7684\u7b2c\u4e00\u4e2a\u5bf9\u8c61&#039;&#039;&#039;<\/span><br \/>\nemp1 <span class=\"token operator\">&#061;<\/span> Employee<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Zaya&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">2000<\/span><span class=\"token punctuation\">)<\/span><br \/>\nemp2 <span class=\"token operator\">&#061;<\/span> Employee<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Mari&#034;<\/span><span class=\"token punctuation\">,<\/span><span class=\"token number\">1000<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h4>\u8bbf\u95ee\u5c5e\u6027<\/h4>\n<p>\u53ef\u4ee5\u4f7f\u7528\u2019.&#039;\u6765\u8bbf\u95ee\u5bf9\u8c61\u7684\u5c5e\u6027<\/p>\n<p>emp1<span class=\"token punctuation\">.<\/span>diplay<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5982\u679c\u4e3apublic\u5219\u53ef\u4ee5\u76f4\u63a5\u4fee\u6539&#xff0c;\u5982\u679c\u4e3aprivate\u5219\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u63a5\u53e3<\/p>\n<hr \/>\n<h4>Python\u5185\u7f6e\u7c7b\u5c5e\u6027<\/h4>\n<ul>\n<li>__dict__ \u7c7b\u7684\u5c5e\u6027&#xff08;\u5305\u542b\u4e00\u4e2a\u5b57\u5178&#xff0c;\u7531\u7c7b\u7684\u6570\u636e\u5c5e\u6027\u7ec4\u6210&#xff09;<\/li>\n<li>__doc__ \u7c7b\u7684\u6587\u6863\u5b57\u7b26\u4e32<\/li>\n<li>__name__ \u7c7b\u540d<\/li>\n<li>__module__ \u7c7b\u5b9a\u4e49\u6240\u5728\u7684\u6a21\u5757<\/li>\n<li>__bases__ \u7c7b\u7684\u6240\u6709\u7236\u7c7b\u6784\u6210\u7684\u5143\u7d20<\/li>\n<\/ul>\n<hr \/>\n<h4>Python\u7684\u5bf9\u8c61\u9500\u6bc1&#xff08;\u5783\u573e\u56de\u6536&#xff09;<\/h4>\n<p>Python \u4f7f\u7528\u4e86\u5f15\u7528\u8ba1\u6570\u8fd9\u4e00\u7b80\u5355\u6280\u672f\u6765\u8ddf\u8e2a\u548c\u56de\u6536\u5783\u573e\u3002<\/p>\n<p>\u5728 Python \u5185\u90e8\u8bb0\u5f55\u7740\u6240\u6709\u4f7f\u7528\u4e2d\u7684\u5bf9\u8c61\u5404\u6709\u591a\u5c11\u5f15\u7528\u3002<\/p>\n<p>\u4e00\u4e2a\u5185\u90e8\u8ddf\u8e2a\u53d8\u91cf&#xff0c;\u79f0\u4e3a\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570\u5668\u3002<\/p>\n<p>\u5f53\u5bf9\u8c61\u88ab\u521b\u5efa\u65f6&#xff0c; \u5c31\u521b\u5efa\u4e86\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570&#xff0c; \u5f53\u8fd9\u4e2a\u5bf9\u8c61\u4e0d\u518d\u9700\u8981\u65f6&#xff0c; \u4e5f\u5c31\u662f\u8bf4&#xff0c; \u8fd9\u4e2a\u5bf9\u8c61\u7684\u5f15\u7528\u8ba1\u6570\u53d8\u4e3a0 \u65f6&#xff0c; \u5b83\u88ab\u5783\u573e\u56de\u6536\u3002\u4f46\u662f\u56de\u6536\u4e0d\u662f&#034;\u7acb\u5373&#034;\u7684&#xff0c; \u7531\u89e3\u91ca\u5668\u5728\u9002\u5f53\u7684\u65f6\u673a&#xff0c;\u5c06\u5783\u573e\u5bf9\u8c61\u5360\u7528\u7684\u5185\u5b58\u7a7a\u95f4\u56de\u6536\u3002<\/p>\n<p>\u5783\u573e\u56de\u6536\u673a\u5236\u4e0d\u4ec5\u9488\u5bf9\u5f15\u7528\u8ba1\u6570\u4e3a0\u7684\u5bf9\u8c61&#xff0c;\u540c\u6837\u4e5f\u53ef\u4ee5\u5904\u7406\u5faa\u73af\u5f15\u7528\u7684\u60c5\u51b5\u3002\u5faa\u73af\u5f15\u7528\u6307\u7684\u662f&#xff0c;\u4e24\u4e2a\u5bf9\u8c61\u76f8\u4e92\u5f15\u7528&#xff0c;\u4f46\u662f\u6ca1\u6709\u5176\u4ed6\u53d8\u91cf\u5f15\u7528\u4ed6\u4eec\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;\u4ec5\u4f7f\u7528\u5f15\u7528\u8ba1\u6570\u662f\u4e0d\u591f\u7684\u3002Python \u7684\u5783\u573e\u6536\u96c6\u5668\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u5f15\u7528\u8ba1\u6570\u5668\u548c\u4e00\u4e2a\u5faa\u73af\u5783\u573e\u6536\u96c6\u5668\u3002\u4f5c\u4e3a\u5f15\u7528\u8ba1\u6570\u7684\u8865\u5145&#xff0c; \u5783\u573e\u6536\u96c6\u5668\u4e5f\u4f1a\u7559\u5fc3\u88ab\u5206\u914d\u7684\u603b\u91cf\u5f88\u5927&#xff08;\u5373\u672a\u901a\u8fc7\u5f15\u7528\u8ba1\u6570\u9500\u6bc1\u7684\u90a3\u4e9b&#xff09;\u7684\u5bf9\u8c61\u3002 \u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c; \u89e3\u91ca\u5668\u4f1a\u6682\u505c\u4e0b\u6765&#xff0c; \u8bd5\u56fe\u6e05\u7406\u6240\u6709\u672a\u5f15\u7528\u7684\u5faa\u73af\u3002<\/p>\n<p><span class=\"token comment\">#!\/usr\/bin\/python<\/span><br \/>\n<span class=\"token comment\"># -*- coding: UTF-8 -*-<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Point<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> x<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">,<\/span> y<span class=\"token operator\">&#061;<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>x <span class=\"token operator\">&#061;<\/span> x<br \/>\n        self<span class=\"token punctuation\">.<\/span>y <span class=\"token operator\">&#061;<\/span> y<\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__del__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        class_name <span class=\"token operator\">&#061;<\/span> self<span class=\"token punctuation\">.<\/span>__class__<span class=\"token punctuation\">.<\/span>__name__<br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>class_name<span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;\u9500\u6bc1&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>pt1 <span class=\"token operator\">&#061;<\/span> Point<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\npt2 <span class=\"token operator\">&#061;<\/span> pt1<br \/>\npt3 <span class=\"token operator\">&#061;<\/span> pt1<br \/>\n<span class=\"token keyword\">print<\/span><br \/>\n<span class=\"token builtin\">id<\/span><span class=\"token punctuation\">(<\/span>pt1<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">id<\/span><span class=\"token punctuation\">(<\/span>pt2<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token builtin\">id<\/span><span class=\"token punctuation\">(<\/span>pt3<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u6253\u5370\u5bf9\u8c61\u7684id<\/span><br \/>\n<span class=\"token keyword\">del<\/span> pt1<br \/>\n<span class=\"token keyword\">del<\/span> pt2<br \/>\n<span class=\"token keyword\">del<\/span> pt3<\/p>\n<p>2256516188960 2256516188960 2256516188960<br \/>\nPoint \u9500\u6bc1<\/p>\n<h4>\u7c7b\u7684\u7ee7\u627f<\/h4>\n<p>\u7ee7\u627f\u8bed\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">class<\/span> \u6d3e\u751f\u7c7b\u540d\u5b57<span class=\"token punctuation\">(<\/span>\u57fa\u7c7b\u540d\u5b57<span class=\"token punctuation\">)<\/span><\/p>\n<p>\u5728Python\u4e2d\u7ee7\u627f\u7684\u4e00\u4e9b\u7279\u70b9<\/p>\n<li>\u5982\u679c\u5728\u5b50\u7c7b\u4e2d\u9700\u8981\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u5c31\u9700\u8981\u663e\u5f0f\u7684\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5&#xff0c;\u6216\u8005\u4e0d\u91cd\u5199\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u3002<br \/>\n2&#xff09;\u5728\u8c03\u7528\u57fa\u7c7b\u7684\u65b9\u6cd5\u65f6&#xff0c;\u9700\u8981\u52a0\u4e0a\u57fa\u7c7b\u7684\u7c7b\u540d\u524d\u7f00&#xff0c;\u4e14\u9700\u8981\u5e26\u4e0a self \u53c2\u6570\u53d8\u91cf\u3002\u533a\u522b\u5728\u4e8e\u7c7b\u4e2d\u8c03\u7528\u666e\u901a\u51fd\u6570\u65f6\u5e76\u4e0d\u9700\u8981\u5e26\u4e0a self \u53c2\u6570\u3002<br \/>\n3&#xff09;Python \u603b\u662f\u9996\u5148\u67e5\u627e\u5bf9\u5e94\u7c7b\u578b\u7684\u65b9\u6cd5&#xff0c;\u5982\u679c\u5b83\u4e0d\u80fd\u5728\u6d3e\u751f\u7c7b\u4e2d\u627e\u5230\u5bf9\u5e94\u7684\u65b9\u6cd5&#xff0c;\u5b83\u624d\u5f00\u59cb\u5230\u57fa\u7c7b\u4e2d\u9010\u4e2a\u67e5\u627e\u3002&#xff08;\u5148\u5728\u672c\u7c7b\u4e2d\u67e5\u627e\u8c03\u7528\u7684\u65b9\u6cd5&#xff0c;\u627e\u4e0d\u5230\u624d\u53bb\u57fa\u7c7b\u4e2d\u627e\u3002<\/li>\n<p>\u6bd4\u5982\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Parent<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8c03\u7528\u4e86\u7236\u7c7b\u7684\u6784\u9020\u5668&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__del__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8c03\u7528\u4e86\u7236\u7c7b\u7684\u6790\u6784\u5668&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Child<\/span><span class=\"token punctuation\">(<\/span>Parent<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8c03\u7528\u4e86\u5b50\u7c7b\u7684\u6784\u9020\u5668&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__del__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8c03\u7528\u4e86\u5b50\u7c7b\u7684\u6790\u6784\u5668&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>c <span class=\"token operator\">&#061;<\/span> Child<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8c03\u7528\u4e86\u5b50\u7c7b\u7684\u6784\u9020\u5668<br \/>\n\u8c03\u7528\u4e86\u5b50\u7c7b\u7684\u6790\u6784\u5668<\/p>\n<p>\u4e0a\u8ff0\u4f8b\u5b50\u4e2d&#xff0c;\u91cd\u5199\u4e86\u7236\u7c7b\u7684\u6784\u9020\u5668&#xff0c;\u56e0\u6b64Python\u4e0d\u4f1a\u8fdb\u5165\u7236\u7c7b\u8fdb\u884c\u6784\u9020&#xff0c;\u4e5f\u5c31\u4e0d\u4f1a\u89e6\u53d1\u7236\u7c7b\u7684\u6784\u9020\u5668\u3002\u8fd9\u79cd\u673a\u5236\u4f3c\u4e4e\u5bf9\u4e8e\u6790\u6784\u5668\u4e5f\u4f1a\u751f\u6548\u3002<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Parent<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8c03\u7528\u4e86\u7236\u7c7b\u7684\u6784\u9020\u5668&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__del__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8c03\u7528\u4e86\u7236\u7c7b\u7684\u6790\u6784\u5668&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Child<\/span><span class=\"token punctuation\">(<\/span>Parent<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">pass<\/span><br \/>\n    <span class=\"token comment\"># def __init__(self):<\/span><br \/>\n       <span class=\"token comment\"># print(&#034;\u8c03\u7528\u4e86\u5b50\u7c7b\u7684\u6784\u9020\u5668&#034;)<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__del__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8c03\u7528\u4e86\u5b50\u7c7b\u7684\u6790\u6784\u5668&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>c <span class=\"token operator\">&#061;<\/span> Child<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u8c03\u7528\u4e86\u7236\u7c7b\u7684\u6784\u9020\u5668<br \/>\n\u8c03\u7528\u4e86\u5b50\u7c7b\u7684\u6790\u6784\u5668<\/p>\n<p>Python\u652f\u6301\u591a\u7ee7\u627f<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">SubClassName<\/span><span class=\"token punctuation\">(<\/span>ParentName1<span class=\"token punctuation\">,<\/span>ParentName2<span class=\"token punctuation\">,<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">.<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h4>\u65b9\u6cd5\u91cd\u5199&#xff08;\u91cd\u8f7d&#xff09;<\/h4>\n<p>\u5982\u679c\u5bf9\u7236\u7c7b\u7684\u65b9\u6cd5\u4e0d\u6ee1\u610f&#xff0c;\u90a3\u4e48\u5c31\u53ef\u4ee5\u6267\u884c\u91cd\u8f7d\u64cd\u4f5c&#xff0c;\u8fd9\u65f6\u5019Python\u4f1a\u4f18\u5148\u8c03\u7528\u5b50\u7c7b\u7684\u65b9\u6cd5<\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Parent<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">show<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u662f\u7236&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Child<\/span><span class=\"token punctuation\">(<\/span>Parent<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">show<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u6211\u662f\u5b50&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>child <span class=\"token operator\">&#061;<\/span> Child<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\nchild<span class=\"token punctuation\">.<\/span>show<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<hr \/>\n<h4>\u57fa\u7840\u91cd\u8f7d\u65b9\u6cd5<\/h4>\n<p>\u4e0b\u6807\u5217\u51fa\u4e86\u4e00\u4e9b\u57fa\u7840\u7684\u91cd\u8f7d\u65b9\u6cd5<\/p>\n<table>\n<tr>\u5e8f\u53f7\u65b9\u6cd5\u3001\u63cf\u8ff0&amp;\u7b80\u5355\u7684\u5e94\u7528<\/tr>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>__init__(args)  \u6784\u9020\u51fd\u6570:  obj&#061;className(args)<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>__del__(self) \u6790\u6784\u51fd\u6570: del obj<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>__repr__(self)  \u8f6c\u5316\u4e3a\u4f9b\u89e3\u91ca\u5668\u8bfb\u53d6\u7684\u5f62\u5f0f: repr(obj)<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>__str__(self)  \u8f6c\u5316\u4e3a\u9002\u7528\u4e8e\u4eba\u9605\u8bfb\u7684\u5f62\u5f0f: str(obj)<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td>__cmp__(self,x)  \u5bf9\u8c61\u95f4\u7684\u6bd4\u8f83: cmp(obj,x)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h4>\u8fd0\u7b97\u7b26\u91cd\u8f7d<\/h4>\n<p>Python\u540c\u6837\u652f\u6301\u8fd0\u7b97\u7b26\u91cd\u8f7d&#xff0c;\u5b9e\u73b0\u65b9\u6cd5\u5982\u4e0b<\/p>\n<p><span class=\"token comment\">#!\/usr\/bin\/python<\/span><\/p>\n<p><span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Vector<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__init__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> a<span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        self<span class=\"token punctuation\">.<\/span>a <span class=\"token operator\">&#061;<\/span> a<br \/>\n        self<span class=\"token punctuation\">.<\/span>b <span class=\"token operator\">&#061;<\/span> b<\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__str__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#039;Vector (%d, %d)&#039;<\/span> <span class=\"token operator\">%<\/span> <span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">.<\/span>a<span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>b<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">def<\/span> <span class=\"token function\">__add__<\/span><span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">,<\/span> other<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> Vector<span class=\"token punctuation\">(<\/span>self<span class=\"token punctuation\">.<\/span>a <span class=\"token operator\">&#043;<\/span> other<span class=\"token punctuation\">.<\/span>a<span class=\"token punctuation\">,<\/span> self<span class=\"token punctuation\">.<\/span>b <span class=\"token operator\">&#043;<\/span> other<span class=\"token punctuation\">.<\/span>b<span class=\"token punctuation\">)<\/span><\/p>\n<p>v1 <span class=\"token operator\">&#061;<\/span> Vector<span class=\"token punctuation\">(<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">10<\/span><span class=\"token punctuation\">)<\/span><br \/>\nv2 <span class=\"token operator\">&#061;<\/span> Vector<span class=\"token punctuation\">(<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span>v1 <span class=\"token operator\">&#043;<\/span> v2<span class=\"token punctuation\">)<\/span><\/p>\n<p>Vector(7,8)<\/p>\n<hr \/>\n<h4>\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/h4>\n<p>\u8fd9\u4e2a\u5373\u8bbf\u95ee\u63a7\u5236\u7b26<\/p>\n<h5>\u79c1\u6709\u5c5e\u6027<\/h5>\n<ul>\n<li>\u4f7f\u7528\u53cc\u4e0b\u6ed1\u7ebf\u8fdb\u884c\u58f0\u660e&#xff0c;\u6307\u793a\u8fd9\u4e2a\u5c5e\u6027\u4e3a\u4f3c\u6709&#xff0c;\u4e0d\u80fd\u5728\u7c7b\u7684\u5916\u90e8\u88ab\u4f7f\u7528\u6216\u8005\u76f4\u63a5\u8bbf\u95ee&#xff0c;\u5728\u5185\u90e8\u53ef\u4ee5\u8fdb\u884c\u8bbf\u95ee<\/li>\n<li>__private_attrs<\/li>\n<\/ul>\n<h5>\u7c7b\u7684\u65b9\u6cd5<\/h5>\n<ul>\n<li>\u5728\u7c7b\u7684\u5185\u90e8&#xff0c;\u4f7f\u7528def\u5173\u952e\u5b57\u53ef\u4ee5\u4e3a\u7c7b\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5&#xff0c;\u548c\u4e00\u822c\u7684\u51fd\u6570\u5b9a\u4e49\u4e0d\u540c&#xff0c;\u7c7b\u65b9\u6cd5\u5fc5\u987b\u5305\u542b\u53c2\u6570self&#xff0c;\u4e14\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570<\/li>\n<\/ul>\n<h5>\u7c7b\u7684\u79c1\u6709\u65b9\u6cd5<\/h5>\n<ul>\n<li>\u4e24\u4e2a\u4e0b\u5212\u7ebf\u5f00\u5934&#xff0c;\u58f0\u660e\u8be5\u65b9\u6cd5\u4e3a\u79c1\u6709\u65b9\u6cd5&#xff0c;\u4e0d\u80fd\u5728\u7c7b\u7684\u5916\u90e8\u8fdb\u884c\u8c03\u7528&#xff0c;\u5728\u7c7b\u7684\u5185\u90e8\u8fdb\u884c\u8c03\u7528<\/li>\n<li>__private_method<\/li>\n<\/ul>\n<hr \/>\n<h5>\u8bbf\u95ee\u63a7\u5236<\/h5>\n<p>Python\u7684\u8bbf\u95ee\u63a7\u5236\u975e\u5e38\u6709\u610f\u601d<\/p>\n<li>\u65e0\u4e0b\u5212\u7ebf\u5f00\u5934foo \u4e00\u822c\u4e3apublic\u5c5e\u6027<\/li>\n<li>\u5355\u4e0b\u5212\u7ebf\u5f00\u5934_foo \u4e00\u822c\u4e3aprotected\u5c5e\u6027<\/li>\n<li>\u53cc\u4e0b\u5212\u7ebf\u5f00\u5934__foo\u4e00\u822c\u4e3aprivate\u5c5e\u6027<\/li>\n<li>\u53cc\u5934\u53cc\u5c3e__foo__ \u4e00\u822c\u4e3a\u7cfb\u7edf\u5b9a\u4e49\u7684\u540d\u5b57&#xff0c;\u5982__init__<\/li>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb140\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Python\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5305\u62ec\u7c7b\u7684\u521b\u5efa\u3001\u5b9e\u4f8b\u5316\u3001\u8bbf\u95ee\u5c5e\u6027\u3001\u5185\u7f6e\u7c7b\u5c5e\u6027\u3001\u5bf9\u8c61\u9500\u6bc1\u673a\u5236\u7b49\u3002\u91cd\u70b9\u8bb2\u89e3\u4e86\u7c7b\u7684\u7ee7\u627f\u3001\u65b9\u6cd5\u91cd\u5199\u3001\u8fd0\u7b97\u7b26\u91cd\u8f7d\u4ee5\u53ca\u8bbf\u95ee\u63a7\u5236\u7b49\u7279\u6027\u3002\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u6784\u9020\u5668__init__\u548c\u6790\u6784\u5668__del__\uff0c\u4ee5\u53caself\u53c2\u6570\u7684\u4f5c\u7528\u3002\u6587\u7ae0\u8fd8\u8be6\u7ec6\u8bf4\u660e\u4e86Python\u7684\u5783\u573e\u56de\u6536\u673a\u5236\u3001\u591a\u7ee7\u627f\u652f\u6301\u3001\u5c5e\u6027\u8bbf\u95ee\u63a7\u5236\u89c4\u5219\uff08public\/protected\/private\uff09\u7b49\u5185\u5bb9\u3002\u8fd9\u4e9b\u77e5\u8bc6\u70b9\u662fPython\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u57fa\u7840\uff0c\u5bf9\u4e8e\u7406\u89e3\u548c\u4f7f\u7528Python\u7c7b\u4e0e\u5bf9\u8c61\u975e\u5e38\u91cd\u8981\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":[890,1032,99,81,4596,190,43,44],"topic":[],"class_list":{"0":"post-47801","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-django","8":"tag-gunicorn","9":"tag-java","10":"tag-python","12":"tag-190","13":"tag-43","14":"tag-44"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5 - \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\/47801.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb140\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Python\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5305\u62ec\u7c7b\u7684\u521b\u5efa\u3001\u5b9e\u4f8b\u5316\u3001\u8bbf\u95ee\u5c5e\u6027\u3001\u5185\u7f6e\u7c7b\u5c5e\u6027\u3001\u5bf9\u8c61\u9500\u6bc1\u673a\u5236\u7b49\u3002\u91cd\u70b9\u8bb2\u89e3\u4e86\u7c7b\u7684\u7ee7\u627f\u3001\u65b9\u6cd5\u91cd\u5199\u3001\u8fd0\u7b97\u7b26\u91cd\u8f7d\u4ee5\u53ca\u8bbf\u95ee\u63a7\u5236\u7b49\u7279\u6027\u3002\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u6784\u9020\u5668__init__\u548c\u6790\u6784\u5668__del__\uff0c\u4ee5\u53caself\u53c2\u6570\u7684\u4f5c\u7528\u3002\u6587\u7ae0\u8fd8\u8be6\u7ec6\u8bf4\u660e\u4e86Python\u7684\u5783\u573e\u56de\u6536\u673a\u5236\u3001\u591a\u7ee7\u627f\u652f\u6301\u3001\u5c5e\u6027\u8bbf\u95ee\u63a7\u5236\u89c4\u5219\uff08public\/protected\/private\uff09\u7b49\u5185\u5bb9\u3002\u8fd9\u4e9b\u77e5\u8bc6\u70b9\u662fPython\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u57fa\u7840\uff0c\u5bf9\u4e8e\u7406\u89e3\u548c\u4f7f\u7528Python\u7c7b\u4e0e\u5bf9\u8c61\u975e\u5e38\u91cd\u8981\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/47801.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T01:22:32+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\/47801.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/47801.html\",\"name\":\"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T01:22:32+00:00\",\"dateModified\":\"2025-07-30T01:22:32+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/47801.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/47801.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/47801.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5\"}]},{\"@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":"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5 - \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\/47801.html","og_locale":"zh_CN","og_type":"article","og_title":"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb140\u6b21\u3002\u672c\u6587\u4ecb\u7ecd\u4e86Python\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\uff0c\u5305\u62ec\u7c7b\u7684\u521b\u5efa\u3001\u5b9e\u4f8b\u5316\u3001\u8bbf\u95ee\u5c5e\u6027\u3001\u5185\u7f6e\u7c7b\u5c5e\u6027\u3001\u5bf9\u8c61\u9500\u6bc1\u673a\u5236\u7b49\u3002\u91cd\u70b9\u8bb2\u89e3\u4e86\u7c7b\u7684\u7ee7\u627f\u3001\u65b9\u6cd5\u91cd\u5199\u3001\u8fd0\u7b97\u7b26\u91cd\u8f7d\u4ee5\u53ca\u8bbf\u95ee\u63a7\u5236\u7b49\u7279\u6027\u3002\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528\u6784\u9020\u5668__init__\u548c\u6790\u6784\u5668__del__\uff0c\u4ee5\u53caself\u53c2\u6570\u7684\u4f5c\u7528\u3002\u6587\u7ae0\u8fd8\u8be6\u7ec6\u8bf4\u660e\u4e86Python\u7684\u5783\u573e\u56de\u6536\u673a\u5236\u3001\u591a\u7ee7\u627f\u652f\u6301\u3001\u5c5e\u6027\u8bbf\u95ee\u63a7\u5236\u89c4\u5219\uff08public\/protected\/private\uff09\u7b49\u5185\u5bb9\u3002\u8fd9\u4e9b\u77e5\u8bc6\u70b9\u662fPython\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u57fa\u7840\uff0c\u5bf9\u4e8e\u7406\u89e3\u548c\u4f7f\u7528Python\u7c7b\u4e0e\u5bf9\u8c61\u975e\u5e38\u91cd\u8981\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/47801.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T01:22:32+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\/47801.html","url":"https:\/\/www.wsisp.com\/helps\/47801.html","name":"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T01:22:32+00:00","dateModified":"2025-07-30T01:22:32+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/47801.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/47801.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/47801.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python\u9762\u5411\u5bf9\u8c61\u7684\u5199\u6cd5"}]},{"@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\/47801","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=47801"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/47801\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=47801"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=47801"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=47801"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=47801"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}