{"id":4237,"date":"2025-06-01T13:10:12","date_gmt":"2025-06-04T06:09:12","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=4237"},"modified":"2025-06-04T13:10:12","modified_gmt":"2025-06-04T06:09:12","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e4%b8%ad%e7%9a%84methods%e5%87%bd%e6%95%b8-5","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e4%b8%ad%e7%9a%84methods%e5%87%bd%e6%95%b8-5\/","title":{"rendered":"\u6df1\u5165\u63a2\u7d22 Python \u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 `methods()` \u51fd\u6578\u7684\u6700\u4f73\u5be6\u8e10"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Python, methods, \u51fd\u6578\u6559\u5b78, Python \u6559\u5b78, Python \u7a0b\u5f0f\u8a2d\u8a08\"><\/p>\n<h1>\u6df1\u5165\u63a2\u7d22 Python \u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 `methods()` \u51fd\u6578\u7684\u6700\u4f73\u5be6\u8e10<\/h1>\n<p>Python \u662f\u4e00\u9580\u529f\u80fd\u5f37\u5927\u4e14\u6613\u65bc\u5b78\u7fd2\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u6578\u64da\u5206\u6790\u3001\u7db2\u7ad9\u958b\u767c\u548c\u81ea\u52d5\u5316\u7b49\u9818\u57df\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0e Python \u4e2d\u7684 `methods()` \u51fd\u6578\uff0c\u5e6b\u52a9\u4f60\u638c\u63e1\u5176\u7528\u6cd5\u548c\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u4ec0\u9ebc\u662f `methods()` \u51fd\u6578\uff1f<\/h2>\n<p>\u5728 Python \u4e2d\uff0c`methods()` \u51fd\u6578\u4e26\u4e0d\u662f\u4e00\u500b\u5167\u5efa\u51fd\u6578\uff0c\u4f46\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 `dir()` \u51fd\u6578\u4f86\u5217\u51fa\u4e00\u500b\u5c0d\u8c61\u7684\u6240\u6709\u65b9\u6cd5\u3002\u9019\u5c0d\u65bc\u4e86\u89e3\u4e00\u500b\u5c0d\u8c61\u7684\u53ef\u7528\u529f\u80fd\u975e\u5e38\u6709\u5e6b\u52a9\u3002\u9019\u88e1\u6709\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<p>&#8220;`python<br \/>\nclass MyClass:<br \/>\n    def my_method(self):<br \/>\n        pass<\/p>\n<p># \u67e5\u770b MyClass \u7684\u6240\u6709\u65b9\u6cd5<br \/>\nprint(dir(MyClass))<br \/>\n&#8220;`<\/p>\n<p>\u9019\u6bb5\u7a0b\u5f0f\u78bc\u6703\u5217\u51fa `MyClass` \u7684\u6240\u6709\u5c6c\u6027\u548c\u65b9\u6cd5\uff0c\u8b93\u6211\u5011\u80fd\u5920\u5feb\u901f\u7406\u89e3\u9019\u500b\u985e\u5225\u7684\u7d50\u69cb\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 `dir()` \u51fd\u6578\u67e5\u8a62\u5c0d\u8c61\u7684\u65b9\u6cd5<\/h2>\n<p>\u4f7f\u7528 `dir()` \u51fd\u6578\u975e\u5e38\u7c21\u55ae\u3002\u4f60\u53ea\u9700\u8981\u5c07\u5c0d\u8c61\u4f5c\u70ba\u53c3\u6578\u50b3\u905e\u7d66 `dir()`\uff0c\u5b83\u5c07\u8fd4\u56de\u4e00\u500b\u5305\u542b\u6240\u6709\u53ef\u7528\u5c6c\u6027\u548c\u65b9\u6cd5\u7684\u5217\u8868\u3002\u4ee5\u4e0b\u662f\u53e6\u4e00\u500b\u7bc4\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 `dir()` \u4f86\u6aa2\u67e5\u4e00\u500b\u5b57\u7b26\u4e32\u5c0d\u8c61\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>&#8220;`python<br \/>\nmy_string = &#8220;Hello, Python!&#8221;<br \/>\nprint(dir(my_string))<br \/>\n&#8220;`<\/p>\n<p>\u9019\u5c07\u5217\u51fa\u6240\u6709\u5b57\u7b26\u4e32\u5c0d\u8c61\u7684\u53ef\u7528\u65b9\u6cd5\uff0c\u4f8b\u5982 `upper()`\u3001`lower()` \u548c `split()` \u7b49\uff0c\u9019\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u66f4\u6709\u6548\u5730\u8655\u7406\u5b57\u7b26\u4e32\u3002<\/p>\n<h2>\u6700\u4f73\u5be6\u8e10\uff1a\u4f7f\u7528\u5e6b\u52a9\u6587\u6a94<\/h2>\n<p>\u9664\u4e86\u4f7f\u7528 `dir()` \u51fd\u6578\u5916\uff0c\u4e86\u89e3\u6bcf\u500b\u65b9\u6cd5\u7684\u5177\u9ad4\u7528\u6cd5\u4e5f\u975e\u5e38\u91cd\u8981\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 `help()` \u51fd\u6578\u4f86\u7372\u53d6\u65b9\u6cd5\u7684\u8a73\u7d30\u4fe1\u606f\u3002\u4f8b\u5982\uff0c\u60f3\u8981\u4e86\u89e3 `list` \u985e\u5225\u7684 `append()` \u65b9\u6cd5\uff1a<\/p>\n<p>&#8220;`python<br \/>\nhelp(list.append)<br \/>\n&#8220;`<\/p>\n<p>\u9019\u5c07\u986f\u793a `append()` \u65b9\u6cd5\u7684\u6587\u6a94\uff0c\u5e6b\u52a9\u4f60\u7406\u89e3\u5176\u7528\u6cd5\u548c\u53c3\u6578\u3002<\/p>\n<h2>\u7e3d\u7d50<\/h2>\n<p>\u5728 Python \u4e2d\uff0c\u4e86\u89e3\u5982\u4f55\u4f7f\u7528 `methods()` \u51fd\u6578\uff08\u5be6\u969b\u4e0a\u662f\u4f7f\u7528 `dir()` \u548c `help()` \u51fd\u6578\uff09\u5c0d\u65bc\u638c\u63e1\u5c0d\u8c61\u7684\u529f\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u900f\u904e\u9019\u4e9b\u5de5\u5177\uff0c\u4f60\u53ef\u4ee5\u5feb\u901f\u67e5\u627e\u548c\u7406\u89e3\u5c0d\u8c61\u7684\u65b9\u6cd5\uff0c\u5f9e\u800c\u63d0\u9ad8\u4f60\u7684\u7de8\u7a0b\u6548\u7387\u3002\u5e0c\u671b\u9019\u7bc7\u6587\u7ae0\u80fd\u5e6b\u52a9\u4f60\u66f4\u6df1\u5165\u5730\u4e86\u89e3 Python \u7684\u65b9\u6cd5\u4f7f\u7528\uff01<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Python\u4e2d\u7684methods()\u51fd\u6578\uff0c\u8b93\u4f60\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u4f7f\u7528Python\u7a0b\u5f0f\u8a9e\u8a00\u3002\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0emethods()\u51fd\u6578\u7684\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u63d0\u9ad8\u7a0b\u5f0f\u7684\u6548\u7387\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-4237","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-16l","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=4237"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4237\/revisions"}],"predecessor-version":[{"id":4238,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/4237\/revisions\/4238"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=4237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=4237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=4237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}