{"id":93847,"date":"2026-08-13T10:25:12","date_gmt":"2026-08-13T02:25:12","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/93847.html"},"modified":"2026-08-13T10:25:12","modified_gmt":"2026-08-13T02:25:12","slug":"python-%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/93847.html","title":{"rendered":"Python \u57fa\u7840\u77e5\u8bc6"},"content":{"rendered":"<h2>Python\u7a0b\u5e8f<\/h2>\n<h3 id=\"Python%E4%BA%A4%E4%BA%92%E6%A8%A1%E5%BC%8F\">Python\u4ea4\u4e92\u6a21\u5f0f<\/h3>\n<p><span style=\"color:#6eaad7\">\u6572\u4e0b\u547d\u4ee4&#xff1a;<\/span><span style=\"color:#98c091\">python3 <\/span><span style=\"color:#a2e043\"> <\/span> <span style=\"color:#6eaad7\">\u63d0\u793a\u7b26&#xff1a;<\/span><span style=\"color:#98c091\">&gt;&gt;&gt; <\/span> \u8f93\u5165<span style=\"color:#98c091\">exit() <\/span>\u5e76\u56de\u8f66 \u9000\u51fa <span style=\"color:#6eaad7\">python\u4ea4\u4e92\u6a21\u5f0f<\/span> \u56de\u5230 <span style=\"color:#6eaad7\">\u547d\u4ee4\u884c\u6a21\u5f0f<\/span><\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"204\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022507-6a7d2b036c009.png\" width=\"1144\" \/><\/p>\n<p><span style=\"color:#98c091\">.py<\/span> \u6587\u4ef6 \u53ea\u80fd\u5728 \u547d\u4ee4\u884c\u6a21\u5f0f <span style=\"color:#98c091\">python3 hello.py <\/span><span style=\"color:#333333\">&#8212;-&gt; \u8def\u5f84\u5728 Python \u4e2d<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"58\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022508-6a7d2b045d817.png\" width=\"788\" \/><\/p>\n<h3 id=\"%E5%91%BD%E4%BB%A4%E8%A1%8C%E6%A8%A1%E5%BC%8F%E5%92%8CPython%E4%BA%A4%E4%BA%92%E6%A8%A1%E5%BC%8F\">\u547d\u4ee4\u884c\u6a21\u5f0f\u548cPython\u4ea4\u4e92\u6a21\u5f0f<\/h3>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"300\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022508-6a7d2b04b373e.png\" width=\"1140\" \/><\/p>\n<h4 id=\"Python%E4%BA%A4%E4%BA%92%E5%BC%8F%E7%8E%AF%E5%A2%83%E4%B8%8B\"><span style=\"color:#494949\">Python\u4ea4\u4e92\u5f0f\u73af\u5883\u4e0b<\/span><\/h4>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"206\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022509-6a7d2b0555298.png\" width=\"1200\" \/><\/p>\n<h3 id=\"%E8%BE%93%E5%87%BA\">\u8f93\u51fa<\/h3>\n<p>&gt;&gt;&gt; print(&#039;hello,world&#039;,&#039;relaxing atmosphere&#039;,&#039;working atmosphere&#039;)<br \/>\n# hello,world  relaxing atmosphere  working atmosphere<br \/>\n&gt;&gt;&gt; print(100&#043;300)<br \/>\n# 400<br \/>\n&gt;&gt;&gt; print(400)<br \/>\n# 400<br \/>\n&gt;&gt;&gt; print(&#039;100 &#043; 300 &#061;&#039;,100 &#043; 300)<br \/>\n# 100 &#043; 300 &#061; 400 <\/p>\n<h3 id=\"%E8%BE%93%E5%85%A5\">\u8f93\u5165<\/h3>\n<p><span style=\"color:#98c091\">input()<\/span> \u7528\u6237\u8f93\u5165 <span style=\"color:#6eaad7\">\u5b57\u7b26\u4e32<\/span> \u5b58\u653e <span style=\"color:#6eaad7\">\u53d8\u91cf <\/span>\u91cc \u53ef\u4ee5\u76f4\u63a5\u8f93\u5165 <span style=\"color:#98c091\">name<\/span> \u67e5\u770b\u53d8\u91cf\u5185\u5bb9 \/ <span style=\"color:#98c091\">print()<\/span>\u51fd\u6570<\/p>\n<p>&gt;&gt;&gt; name &#061; input()<br \/>\n# Smile<br \/>\n&gt;&gt;&gt; name<br \/>\n# &#039;Smile&#039;<br \/>\n&gt;&gt;&gt; print(name)<br \/>\n# Smile<\/p>\n<p># hello.py<br \/>\nname &#061; input(&#039;please enter your name:&#039;)<br \/>\nprint(&#039;hello,&#039;, name)<br \/>\npython3 hello.py<br \/>\nplease enter your name: Smile<br \/>\nhello,SmIle<\/p>\n<h2 id=\"Python%E5%9F%BA%E7%A1%80\">Python\u57fa\u7840<\/h2>\n<h3 id=\"%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%8F%98%E9%87%8F\">\u6570\u636e\u7c7b\u578b\u548c\u53d8\u91cf<\/h3>\n<h4 id=\"%E6%95%B4%E6%95%B0\">\u6574\u6570<\/h4>\n<p>Python \u53ef\u5904\u7406 \u4efb\u610f\u5927\u5c0f\u7684\u6574\u6570 \u5305\u62ec\u8d1f\u6574\u6570<\/p>\n<p><span style=\"color:#6eaad7\">\u4e8c\u8fdb\u5236&#xff1a;<\/span><span style=\"color:#98c091\">\u524d\u7f00 0b\/0B<\/span> <span style=\"color:#9c8ec1\"> 0b1010 ( \u5341\u8fdb\u523610 ) <\/span> <span style=\"color:#6eaad7\">\u5341\u516d\u8fdb\u5236&#xff1a;<\/span> <span style=\"color:#98c091\">\u524d\u7f00 0x \u548c 0-9,a-f<\/span> <span style=\"color:#9c8ec1\">0xa\/0XA<\/span> <span style=\"color:#9c8ec1\">( \u5341\u8fdb\u523610 )<\/span><\/p>\n<p>Python\u5141\u8bb8\u6570\u5b57\u4e2d\u4ee5 <span style=\"color:#98c091\">_<\/span> \u5206\u9694 <span style=\"color:#9c8ec1\"> 10_000_000_000 &#061; 10000000000 0xa1b2_c3d4 &#061; 0xa1b2c3d4<\/span><\/p>\n<h4 id=\"%E6%B5%AE%E7%82%B9%E6%95%B0\">\u6d6e\u70b9\u6570<\/h4>\n<p><span style=\"color:#6eaad7\">\u6d6e\u70b9\u6570<\/span> \u4e5f\u5c31\u662f \u5c0f\u6570 10 \u7528 e \u66ff\u4ee3 <span style=\"color:#9c8ec1\">1.23e9 &#061; 1.23*10^9 \/ 12.3e8 0.000012 &#061; 1.2e-5<\/span><\/p>\n<p>\u6574\u6570\u8fd0\u7b97\u6c38\u8fdc\u662f\u7cbe\u786e\u7684 \u6d6e\u70b9\u6570\u8fd0\u7b97\u53ef\u80fd\u4f1a\u56db\u820d\u4e94\u5165\u7684\u8bef\u5dee<\/p>\n<h4 id=\"%E5%AD%97%E7%AC%A6%E4%B8%B2\">\u5b57\u7b26\u4e32<\/h4>\n<p><span style=\"color:#6eaad7\">\u5b57\u7b26\u4e32<\/span> \u662f\u4ee5 <span style=\"color:#98c091\">\u5355\u5f15\u53f7&#039; <\/span>\u6216 <span style=\"color:#98c091\">\u53cc\u5f15\u53f7 &#034;<\/span> \u62ec\u8d77\u6765\u7684\u4efb\u610f\u6587\u672c <span style=\"color:#9c8ec1\"> &#039;abc&#039; (\u53ea\u6709a,b,c 3\u4e2a\u5b57\u7b26) &#034;where&#034; <\/span><\/p>\n<p><span style=\"color:#9c8ec1\">&#034;I&#039;m ok&#034; (6\u4e2a\u5b57\u7b26) <\/span><span style=\"color:#ed7976\"> \u65e2\u5305\u542b<\/span><span style=\"color:#98c091\">&#039;<\/span><span style=\"color:#ed7976\">\u53c8\u5305\u542b<\/span><span style=\"color:#98c091\"> &#034;<\/span><span style=\"color:#ed7976\"> \u7528 <\/span><span style=\"color:#6eaad7\">\u8f6c\u4e49\u5b57\u7b26<\/span><span style=\"color:#98c091\"> \\\\<\/span><span style=\"color:#ed7976\"> \u6765\u6807\u8bc6 <\/span><span style=\"color:#9c8ec1\"> \u2018I\\\\\u2018m\\\\&#034;OK\\\\&#034;!&#039; &#8212;&#8211;&gt; I &#039;m &#034;OK&#034; !<\/span><\/p>\n<p><span style=\"color:#98c091\">\\\\n<\/span> \u8868\u793a\u6362\u884c <span style=\"color:#98c091\">  \\\\t<\/span>\u8868\u793a\u5236\u8868\u7b26 <span style=\"color:#98c091\"> \\\\\\\\<\/span> \u8868\u793a\u5b57\u7b26\u5c31\u662f\\\\ <span style=\"color:#98c091\">&#039;&#039;&#039;&#8230;&#039;&#039;&#039; <\/span>\u8868\u793a\u591a\u884c\u5185\u5bb9<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"512\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022510-6a7d2b0624474.png\" width=\"688\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"166\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022510-6a7d2b06bf122.png\" width=\"486\" \/><\/p>\n<h4 id=\"%E5%B8%83%E5%B0%94%E5%80%BC\">\u5e03\u5c14\u503c<\/h4>\n<p>\u5e03\u5c14\u503c \u7ecf\u5e38\u7528\u5728 \u6761\u4ef6\u5224\u65ad \u4e2d<\/p>\n<p><span style=\"color:#6eaad7\">\u5e03\u5c14\u503c&#xff1a;<\/span><span style=\"color:#98c091\">True , False<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"214\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022510-6a7d2b06e072f.png\" width=\"438\" \/><\/p>\n<p>\u8fd0\u7b97&#xff1a;and , or , not<\/p>\n<p>and <span style=\"color:#6eaad7\">\u4e0e\u8fd0\u7b97<\/span> \u6240\u6709\u90fd\u662fTrue \u7ed3\u679c\u4e3aTrue<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"116\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b07024d7.png\" width=\"352\" \/><\/p>\n<p>or <span style=\"color:#6eaad7\">\u6216\u8fd0\u7b97<\/span> \u5176\u4e2d\u4e00\u4e2a\u4e3aTrue \u7ed3\u679c\u4e3aTrue<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"166\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b0715fb3.png\" width=\"402\" \/><\/p>\n<p>not <span style=\"color:#6eaad7\">\u975e\u8fd0\u7b97<\/span> \u5355\u76ee\u8fd0\u7b97\u7b26 True\u53d8False False\u53d8True<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"112\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b072b168.png\" width=\"366\" \/><\/p>\n<h4 id=\"%E7%A9%BA%E5%80%BC\">\u7a7a\u503c<\/h4>\n<p><span style=\"color:#6eaad7\">\u7a7a\u503c&#xff1a;<\/span><span style=\"color:#98c091\"> None<\/span> None \u4e0d\u80fd\u7406\u89e3\u4e3a 0 0 \u4e3a\u6709\u610f\u4e49\u7684 None \u662f\u4e00\u4e2a\u7279\u6b8a\u7684\u7a7a\u503c<\/p>\n<h4 id=\"%E5%8F%98%E9%87%8F\">\u53d8\u91cf<\/h4>\n<p>\u53d8\u91cf \u5728\u7a0b\u5e8f\u4e2d\u7528\u4e00\u4e2a \u53d8\u91cf\u540d \u8868\u793a <span style=\"color:#6eaad7\">\u53d8\u91cf\u540d&#xff1a;<\/span>\u5927\u5c0f\u5199\u82f1\u6587\u3001\u6570\u5b57\u548c_ \u7ec4\u5408 <span style=\"color:#ed7976\">\u4e0d\u80fd\u7528\u6570\u5b57\u5f00\u5934<\/span><\/p>\n<p>\u52a8\u6001\u8bed\u8a00  \u53d8\u91cf\u672c\u8eab\u7c7b\u578b \u4e0d\u56fa\u5b9a\u7684\u8bed\u8a00<\/p>\n<p>a &#061; 123 #a\u662f\u6574\u6570<\/p>\n<p>print(a)<\/p>\n<p>a &#061; &#039;ABC&#039; #a\u53d8\u4e3a \u5b57\u7b26\u4e32<\/p>\n<p>print(a)<\/p>\n<p>\u9759\u6001\u8bed\u8a00 \u5b9a\u4e49\u53d8\u91cf\u65f6 \u5fc5\u987b\u6307\u5b9a\u53d8\u91cf\u7c7b\u578b \u5982\u679c\u8d4b\u503c\u7c7b\u578b\u4e0d\u5339\u914d <span style=\"color:#ed7976\">\u62a5\u9519<\/span><\/p>\n<p>\/\/ Java \u662f\u9759\u6001\u8bed\u8a00<\/p>\n<p>int a &#061; 123; \/\/ a \u6574\u6570\u7c7b\u578b\u53d8\u91cf<\/p>\n<p>a &#061; &#034;ABC&#034;; \/\/ \u9519\u8bef&#xff1a;\u4e0d\u80fd\u628a \u5b57\u7b26\u4e32 \u8d4b\u7ed9 \u6574\u578b\u53d8\u91cf<\/p>\n<p>a &#061; &#039;ABC&#039;<\/p>\n<p>Python \u89e3\u91ca\u5668&#xff1a;<\/p>\n<p>1. \u5185\u5b58\u4e2d \u521b\u5efa\u4e00\u4e2a &#039;ABC&#039; \u5b57\u7b26\u4e32<\/p>\n<p>2.\u5185\u5b58\u4e2d \u521b\u5efa\u4e00\u4e2a\u540d\u4e3a a \u7684\u53d8\u91cf \u5e76 \u6307\u5411 &#039;ABC&#039;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"262\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b073ce05.png\" width=\"874\" \/><\/p>\n<h4 id=\"%E5%B8%B8%E9%87%8F\">\u5e38\u91cf<\/h4>\n<p><span style=\"color:#6eaad7\">\u5e38\u91cf&#xff1a;<\/span>\u4e0d\u80fd\u53d8\u7684\u53d8\u91cf \u5168\u90e8\u5927\u5199\u7684\u53d8\u91cf <span style=\"color:#9c8ec1\">\u5e38\u6570\u03c0 MA &#061; 3.141592653589<\/span><\/p>\n<h3 id=\"Python%E9%99%A4%E6%B3%95\">Python\u9664\u6cd5<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"210\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b0760343.png\" width=\"486\" \/><\/p>\n<h3 id=\"%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%92%8C%E7%BC%96%E7%A0%81\">\u5b57\u7b26\u4e32\u548c\u7f16\u7801<\/h3>\n<h4 id=\"%E5%AD%97%E7%AC%A6%E7%BC%96%E7%A0%81\">\u5b57\u7b26\u7f16\u7801<\/h4>\n<p>\u7f16\u7801\u51fa\u73b0\u7684\u5e95\u5c42\u539f\u56e0&#xff1a;\u8ba1\u7b97\u673a\u53ea\u80fd\u5904\u7406\u6570\u5b57 \u6587\u672c\u9700\u8f6c\u5316\u4e3a\u6570\u5b57(\u7f16\u7801)\u624d\u53ef\u88ab\u5904\u7406 \u4e0d\u540c\u8bed\u8a00\u5bf9\u7f16\u7801\u9700\u6c42\u4e0d\u540c<\/p>\n<p>ASCII  <span style=\"color:#9c8ec1\">\u57fa\u7840\u6b3e<\/span> \u57fa\u7840\u5355\u5b50\u8282 \u4ec5\u8986\u76d6\u82f1\u6587\u5b57\u7b26\/\u6570\u5b57\/\u57fa\u7840\u7b26\u53f7(127\u4e2a) \u6240\u6709\u7f16\u7801\u57fa\u7840 \u65e0\u6cd5\u517c\u5bb9\u591a\u8bed\u8a00<\/p>\n<p>Unicode  <span style=\"color:#9c8ec1\">\u7edf\u4e00\u6b3e<\/span> \u7edf\u4e00\u591a\u8bed\u8a00\u5b57\u7b26\u96c6 \u89e3\u51b3\u4e71\u7801\u95ee\u9898 \u5e38\u7528 UCS-16\u7f16\u7801(2\/4\u5b57\u8282 \u56fa\u5b9a\u957f\u5ea6) \u7eaf\u82f1\u4e0b\u6bd4ASCII\u591a\u53601\u500d\u7a7a\u95f4<\/p>\n<p>UTF-8 <span style=\"color:#9c8ec1\">\u5b9e\u7528\u6b3e<\/span> Unicode\u7684\u201c\u53ef\u53d8\u957f\u7f16\u7801\u201d\u5b9e\u73b0 \u517c\u5bb9ASCII \u82f1\u6587(1\u5b57\u8282) \u6c49\u5b57(3\u5b57\u8282) \u751f\u50fb\u5b57\u7b26(1-6\u5b57\u8282) \u517c\u987e\u591a \u8bed\u8a00 \u548c \u5b58\u50a8\/\u4f20\u8f93\u6548\u7387<\/p>\n<h5 id=\"%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%B3%BB%E7%BB%9F%E7%BC%96%E7%A0%81%E5%B7%A5%E4%BD%9C%E6%B5%81%E7%A8%8B\">\u8ba1\u7b97\u673a\u7cfb\u7edf\u7f16\u7801\u5de5\u4f5c\u6d41\u7a0b<\/h5>\n<p>\u5185\u5b58\u4e2d&#xff1a; \u7edf\u4e00\u7528Unicode\u7f16\u7801 &#8212;- \u65b9\u4fbf\u591a\u8bed\u8a00\u5904\u7406<\/p>\n<p>\u5b58\u50a8\/\u4f20\u8f93&#xff08;\u786c\u76d8\/\u7f51\u7edc&#xff09;&#xff1a; \u8f6c\u5316\u4e3a UTF-8\u7f16\u7801 &#8212;- \u8282\u7701\u7a7a\u95f4<\/p>\n<p><span style=\"color:#9c8ec1\">\u8bb0\u4e8b\u672c\u7f16\u8f91\u3001\u7f51\u9875\u6d4f\u89c8\u9075\u5faa\u201c\u8bfb\u53d6UTF-8 &#8211;&gt; \u8f6cUnicode\u5230\u5185\u5b58 &#8211;&gt; \u7f16\u8f91\u540e\u8f6cUTF-8 \u4fdd\u5b58\/\u4f20\u8f93\u201d<\/span><\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>\u7f16\u7801\u7c7b\u578b<\/td>\n<td>\u5b57\u8282\u957f\u5ea6<\/td>\n<td>\u6838\u5fc3\u4f5c\u7528<\/td>\n<td>\u9002\u7528\u573a\u666f<\/td>\n<\/tr>\n<tr>\n<td>ASCII<\/td>\n<td>\u56fa\u5b9a1\u5b57\u8282<\/td>\n<td>\u57fa\u7840\u82f1\u6587\u7f16\u7801<\/td>\n<td>\u5386\u53f2\u9057\u7559\u8f6f\u4ef6\u3001\u7eaf\u82f1\u6587\u6587\u672c<\/td>\n<\/tr>\n<tr>\n<td>Unicode<\/td>\n<td>\u56fa\u5b9a2\/4\u5b57\u8282<\/td>\n<td>\u7edf\u4e00\u591a\u8bed\u8a00\u5b57\u7b26\u96c6<\/td>\n<td>\u8ba1\u7b97\u673a\u5185\u5b58\u5904\u7406\u6587\u672c<\/td>\n<\/tr>\n<tr>\n<td>UTF-8<\/td>\n<td>\u53ef\u53d81-6\u5b57\u8282<\/td>\n<td>\u9ad8\u6548\u5b58\u50a8\/\u4f20\u8f93<\/td>\n<td>\u6587\u4ef6\u4fdd\u5b58\u3001\u7f51\u9875\u4f20\u8f93\u3001\u591a\u8bed\u8a00\u6587\u672c<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 id=\"Python%E5%AD%97%E7%AC%A6%E4%B8%B2\">Python\u5b57\u7b26\u4e32<\/h4>\n<p>Python3 \u5b57\u7b26\u4e32 Unicode\u7f16\u7801<\/p>\n<p><span style=\"color:#98c091\">ord()<\/span>\u51fd\u6570 \u83b7\u53d6\u5b57\u7b26\u6574\u6570\u8868\u793a <span style=\"color:#98c091\"> chr()<\/span>\u51fd\u6570 \u628a\u7f16\u7801\u8f6c\u6362\u4e3a\u5bf9\u5e94\u7684\u5b57\u7b26<\/p>\n<p>print(&#039;\u5305\u542b\u4e2d\u6587\u7684str&#039;)<br \/>\n# \u5305\u542b\u4e2d\u6587\u7684str<br \/>\nord(&#039;A&#039;)<br \/>\n# 65<br \/>\nord(&#039;\u4e2d&#039;)<br \/>\n# 20013<br \/>\nchr(66)<br \/>\n# &#039;B&#039;<br \/>\nchr(25991)<br \/>\n# &#039;\u6587&#039;<\/p>\n<p><span style=\"color:#6eaad7\">Python\u5b57\u7b26\u4e32\u7c7b\u578b<\/span> <span style=\"color:#98c091\">str<\/span><\/p>\n<p>\u5185\u5b58\u4e2d&#xff1a; Unicode 1\u5b57\u7b26\u5bf9\u5e94\u82e5\u5e72\u4e2a\u5b57\u8282<\/p>\n<p>\u5b58\u50a8\/\u4f20\u8f93&#xff08;\u786c\u76d8\/\u7f51\u7edc&#xff09;&#xff1a; str \u53d8\u4e3a\u4ee5 \u5b57\u8282 \u4e3a\u5355\u4f4d\u7684 bytes<\/p>\n<p>Python \u5bf9 bytes \u7c7b\u578b\u6570\u636e \u7528 <span style=\"color:#98c091\">b <\/span> \u524d\u7f00 <span style=\"color:#98c091\">\u5355\u5f15\u53f7<\/span> \u6216 <span style=\"color:#98c091\">\u53cc\u5f15\u53f7<\/span> \u8868\u793a&#xff1a;<\/p>\n<p>x &#061; b&#039;ABC&#039;<\/p>\n<p><span style=\"color:#ed7976\">&#039;ABC&#039; b&#039;ABC&#039; \u524d\u8005\u662f str \u540e\u8005 \u867d\u7136\u5185\u5bb9\u548c\u524d\u8005\u4e00\u6837 \u4f46bytes \u6bcf\u4e2a\u5b57\u7b26\u90fd\u53ea\u5360\u7528\u4e00\u4e2a\u5b57\u8282<\/span><\/p>\n<p>Unicode \u8868\u793a\u7684 <span style=\"color:#98c091\">str<\/span> \u901a\u8fc7 <span style=\"color:#98c091\">encode()<\/span> \u53ef\u7f16\u7801\u4e3a\u6307\u5b9a\u7684 <span style=\"color:#98c091\">bytes<\/span><\/p>\n<p>&gt;&gt;&gt; &#039;ABC&#039;.encode(&#039;ascii&#039;)<br \/>\nb&#039;ABC&#039;<br \/>\n&gt;&gt;&gt; &#039;\u4e2d\u6587&#039;.encode(&#039;utf-8&#039;)<br \/>\nb&#039;\\\\xe4\\\\xb8\\\\xad\\\\xe6\\\\x96\\\\x87&#039;<br \/>\n&gt;&gt;&gt; &#039;\u4e2d\u6587&#039;.encode(&#039;ascii&#039;)<br \/>\nTraceback (most recent call last):<br \/>\n  File &#034;&lt;stdin&gt;&#034;, line 1, in &lt;module&gt;<br \/>\nUnicodeEncodeError: &#039;ascii&#039; codec can&#039;t encode characters in position 0-1: ordinal not in range(128)<\/p>\n<p><span style=\"color:#ed7976\">\u5728bytes\u4e2d \u65e0\u6cd5\u663e\u793a\u4e3aASCII\u5b57\u7b26\u7684\u5b57\u8282 \u7528 <\/span><span style=\"color:#98c091\">\\\\x## <\/span><span style=\"color:#ed7976\">\u663e\u793a<\/span><\/p>\n<p>\u7f51\u7edc\u6216\u786c\u76d8\u8bfb\u53d6\u5b57\u8282\u6d41 \u8bfb\u53d6\u5230\u7684\u6570\u636e\u4e3a bytes bytes&#8212;&gt;str \u7528<span style=\"color:#98c091\">decode()<\/span><\/p>\n<p>&gt;&gt;&gt; b&#039;ABC&#039;.decode(&#039;ascii&#039;)<br \/>\n&#039;ABC&#039;<br \/>\n&gt;&gt;&gt; b&#039;\\\\xe4\\\\xb8\\\\xad\\\\xe6\\\\x96\\\\x87&#039;.decode(&#039;utf-8&#039;)<br \/>\n&#039;\u4e2d\u6587&#039;<\/p>\n<p>bytes\u4e2d \u5305\u542b \u65e0\u6cd5\u89e3\u7801\u7684\u5b57\u8282 decode()\u65b9\u6cd5\u4f1a\u62a5\u9519<\/p>\n<p>&gt;&gt;&gt; b&#039;\\\\xe4\\\\xb8\\\\xad\\\\xff&#039;.decode(&#039;utf-8&#039;)<br \/>\nTraceback (most recent call last):<br \/>\n  &#8230;<br \/>\nUnicodeDecodeError: &#039;utf-8&#039; codec can&#039;t decode byte 0xff in position 3: invalid start byte<\/p>\n<p>bytes\u4e2d \u53ea\u6709\u4e00\u5c0f\u90e8\u5206\u65e0\u6548\u7684\u5b57\u8282 \u53ef\u4f20\u5165 errors&#061;&#039;ignore&#039;\u00a0\u5ffd\u7565\u9519\u8bef\u7684\u5b57\u8282<\/p>\n<p>&gt;&gt;&gt; b&#039;\\\\xe4\\\\xb8\\\\xad\\\\xff&#039;.decode(&#039;utf-8&#039;, errors&#061;&#039;ignore&#039;)<br \/>\n&#039;\u4e2d&#039;<\/p>\n<p>Calculate the number of characters in a <span style=\"color:#98c091\">str<\/span> using the <span style=\"color:#98c091\">len()<\/span> function<\/p>\n<p>&gt;&gt;&gt; len(&#039;ABC&#039;)<br \/>\n3<br \/>\n&gt;&gt;&gt; len(&#039;\u4e2d\u6587&#039;)<br \/>\n2<\/p>\n<p>\u8ba1\u7b97 <span style=\"color:#98c091\">bytes<\/span> \u542b\u591a\u5c11\u5b57\u7b26 <span style=\"color:#98c091\">len()<\/span>\u51fd\u6570<\/p>\n<p>&gt;&gt;&gt; len(b&#039;ABC&#039;)<br \/>\n3<br \/>\n&gt;&gt;&gt; len(b&#039;\\\\xe4\\\\xb8\\\\xad\\\\xe6\\\\x96\\\\x87&#039;)<br \/>\n6<br \/>\n&gt;&gt;&gt; len(&#039;\u4e2d\u6587&#039;.encode(&#039;utf-8&#039;))<br \/>\n6<\/p>\n<p>\u6e90\u4ee3\u7801\u4e2d\u5305\u542b\u4e2d\u6587\u65f6 \u6587\u4ef6\u5f00\u5934\u5199\u5165<\/p>\n<p>#!\/usr\/bin\/env python3<br \/>\n# -*- coding: utf-8 -*-<\/p>\n<p>\u6309\u7167UTF-8\u7f16\u7801\u8bfb\u53d6<\/p>\n<h4 id=\"%E6%A0%BC%E5%BC%8F%E5%8C%96\">\u683c\u5f0f\u5316<\/h4>\n<p><span style=\"color:#98c091\">% \u8fd0\u7b97\u7b26<\/span> \u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/p>\n<p>\u6709\u51e0\u4e2a %? \u5360\u4f4d\u7b26 \u540e\u9762\u5c31\u8ddf\u51e0\u4e2a\u53d8\u91cf\u6216\u503c<\/p>\n<table border=\"1\" cellpadding=\"1\" cellspacing=\"1\" style=\"width:500px\">\n<tbody>\n<tr>\n<td>\u5360\u4f4d\u7b26<\/td>\n<td>\u66ff\u6362\u5185\u5bb9<\/td>\n<\/tr>\n<tr>\n<td>%d<\/td>\n<td>\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>%f<\/td>\n<td>\n<p>\u6d6e\u70b9\u6570<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>%s<\/p>\n<\/td>\n<td>\u5b57\u7b26\u4e32<\/td>\n<\/tr>\n<tr>\n<td>%x<\/td>\n<td>\u5341\u516d\u8fdb\u5236\u6574\u6570<\/td>\n<\/tr>\n<tr>\n<td>%%<\/td>\n<td>%<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"104\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b07725b1.png\" width=\"716\" \/><\/p>\n<h4 id=\"format()%20%E6%A0%BC%E5%BC%8F%E5%8C%96%E5%AD%97%E7%AC%A6%E4%B8%B2\"><span style=\"color:#494949\">format() \u683c\u5f0f\u5316\u5b57\u7b26\u4e32<\/span><\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"58\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b07825a0.png\" width=\"826\" \/><\/p>\n<h4 id=\"f-string\">f-string<\/h4>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"108\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b0794c59.png\" width=\"968\" \/><\/p>\n<p>{r} \u88ab\u53d8\u91cf r \u503c\u66ff\u6362 {s : .2f} \u88ab\u53d8\u91cf s \u503c\u66ff\u6362<\/p>\n<h3 id=\"list%20%E5%92%8C%20tuple\">list \u548c tuple<\/h3>\n<h4 id=\"list\">list<\/h4>\n<p>Python\u5185\u7f6e \u4e00\u79cd \u6570\u636e\u7c7b\u578b \u5217\u8868 list ( \u6709\u5e8f\u96c6\u5408 \u968f\u65f6 \u6dfb\u52a0 \u548c \u5220\u9664 \u5176\u4e2d\u7684\u5143\u7d20)<\/p>\n<p>&gt;&gt;&gt; classmates &#061; [ &#039;Michael&#039;, &#039;LoL&#039;, &#039;Bob&#039;]<br \/>\n&gt;&gt;&gt; classmates<br \/>\n[&#039;Michael&#039;, &#039;LoL&#039;, &#039;Bob&#039;]<br \/>\n#\u53d8\u91cf classmates \u00a0\u5c31\u662f\u4e00\u4e2a list<\/p>\n<h5 id=\"len()%20%E5%87%BD%E6%95%B0\"><span style=\"color:#494949\">len() \u51fd\u6570<\/span><\/h5>\n<p>\u53ef\u4ee5\u83b7\u5f97list \u5143\u7d20 \u4e2a\u6570<\/p>\n<p>&gt;&gt;&gt; len(classmates)<br \/>\n3<\/p>\n<p>\u7d22\u5f15 \u8bbf\u95ee list\u4e2d\u6bcf\u4e00\u4e2a\u5143\u7d20\u4f4d\u7f6e \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <span style=\"color:#ed7976\">\u00a0 \u00a0\u7d22\u5f15\u4ece 0 \u5f00\u59cb<\/span><\/p>\n<p>&gt;&gt;&gt; classmates[0]<br \/>\n&#039;Michael&#039;<br \/>\n&gt;&gt;&gt; classmates[1]<br \/>\n&#039;LoL&#039;<br \/>\n&gt;&gt;&gt; classmates[2]<br \/>\n&#039;Bob&#039;<br \/>\n&gt;&gt;&gt; classmates[3]<br \/>\nTraceback (most recent call last):<br \/>\n  File &#034;&lt;stdin&gt;&#034;, line 1, in &lt;module&gt;<br \/>\nIndexError: list index out of range<br \/>\n#\u7d22\u5f15\u8d85\u51fa\u4e86\u8303\u56f4\u65f6 \u00a0 Python\u4f1a\u62a5\u4e00\u4e2a \u00a0IndexError\u00a0\u9519\u8bef<br \/>\n#\u786e\u4fdd\u7d22\u5f15\u4e0d\u8981\u8d8a\u754c \u00a0 \u6700\u540e\u4e00\u4e2a\u5143\u7d20\u7684\u7d22\u5f15\u662f \u00a0 \u00a0len(classmates) &#8211; 1<\/p>\n<p>-1\u505a\u7d22\u5f15 \u00a0 \u00a0 \u00a0\u76f4\u63a5\u83b7\u53d6\u6700\u540e\u4e00\u4e2a\u5143\u7d20<\/p>\n<p>&gt;&gt;&gt; classmates[-1]<br \/>\n&#039;Bob&#039;<br \/>\n&gt;&gt;&gt; classmates[-2]<br \/>\n&#039;LoL&#039;<br \/>\n&gt;&gt;&gt; classmates[-3]<br \/>\n&#039;Michael&#039;<br \/>\n&gt;&gt;&gt; classmates[-4]<br \/>\nTraceback (most recent call last):<br \/>\n  File &#034;&lt;stdin&gt;&#034;, line 1, in &lt;module&gt;<br \/>\nIndexError: list index out of range<\/p>\n<h5 id=\".append()%20%C2%A0%E8%BF%BD%E5%8A%A0%20%E6%9C%AB%E5%B0%BE\">.append() \u00a0\u8ffd\u52a0 \u672b\u5c3e<\/h5>\n<p>list\u4e2d \u8ffd\u52a0 \u5143\u7d20\u5230\u672b\u5c3e<\/p>\n<p>&gt;&gt;&gt; classmates.append(&#039;Adam&#039;)<br \/>\n&gt;&gt;&gt; classmates<br \/>\n[&#039;Michael&#039;, &#039;Bob&#039;, &#039;Tracy&#039;, &#039;Adam&#039;]<\/p>\n<h5 id=\".insert()%20%E6%8F%92%E5%85%A5%20%E6%8C%87%E5%AE%9A\">.insert() \u63d2\u5165 \u6307\u5b9a<\/h5>\n<p>\u63d2\u5165 \u5230\u6307\u5b9a\u4f4d\u7f6e \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u6bd4\u5982 \u7d22\u5f15\u53f7\u4e3a 1 \u7684\u4f4d\u7f6e<\/p>\n<p>&gt;&gt;&gt; classmates.insert(1, &#039;Jack&#039;)<br \/>\n&gt;&gt;&gt; classmates<br \/>\n[&#039;Michael&#039;, &#039;Jack&#039;, &#039;Bob&#039;, &#039;Tracy&#039;, &#039;Adam&#039;]<\/p>\n<h5 id=\"pop()%20%C2%A0%E5%88%A0%E9%99%A4%20%E6%9C%AB%E5%B0%BE\">pop() \u00a0\u5220\u9664 \u672b\u5c3e<\/h5>\n<p>\u5220\u9664 list \u672b\u5c3e\u5143\u7d20<\/p>\n<p>&gt;&gt;&gt; classmates.pop()<br \/>\n&#039;Adam&#039;<br \/>\n&gt;&gt;&gt; classmates<br \/>\n[&#039;Michael&#039;, &#039;Jack&#039;, &#039;Bob&#039;, &#039;Tracy&#039;]<\/p>\n<h5 id=\"pop(i)%20%C2%A0%E5%88%A0%E9%99%A4%20%E6%8C%87%E5%AE%9A\">pop(i) \u00a0\u5220\u9664 \u6307\u5b9a<\/h5>\n<p>\u5220\u9664 \u6307\u5b9a \u4f4d\u7f6e\u5143\u7d20 \u00a0 \u00a0 \u00a0 i \u662f \u7d22\u5f15\u4f4d\u7f6e<\/p>\n<p>&gt;&gt;&gt; classmates.pop(1)<br \/>\n&#039;Jack&#039;<br \/>\n&gt;&gt;&gt; classmates<br \/>\n[&#039;Michael&#039;, &#039;Bob&#039;, &#039;Tracy&#039;]<\/p>\n<h5 id=\"%E6%9B%BF%E6%8D%A2\">\u66ff\u6362<\/h5>\n<p>\u628a\u67d0\u4e2a\u5143\u7d20 \u66ff\u6362 \u6210\u522b\u7684\u5143\u7d20 \u00a0 \u00a0 \u00a0 \u53ef\u4ee5\u76f4\u63a5\u8d4b\u503c\u7ed9\u5bf9\u5e94\u7684\u7d22\u5f15\u4f4d\u7f6e<\/p>\n<p>&gt;&gt;&gt; classmates[1] &#061; &#039;Sarah&#039;<br \/>\n&gt;&gt;&gt; classmates<br \/>\n[&#039;Michael&#039;, &#039;Sarah&#039;, &#039;Tracy&#039;]<\/p>\n<h5 id=\"%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%8F%AF%E4%B8%8D%E5%90%8C\">\u6570\u636e\u7c7b\u578b\u53ef\u4e0d\u540c<\/h5>\n<p>&gt;&gt;&gt; L &#061; [&#039;Apple&#039;, 123, True]<br \/>\n#list\u5143\u7d20\u4e5f\u53ef\u4ee5\u662f\u53e6\u4e00\u4e2alist<br \/>\n&gt;&gt;&gt; s &#061; [&#039;python&#039;, &#039;java&#039;, [&#039;asp&#039;, &#039;php&#039;], &#039;scheme&#039;]<br \/>\n&gt;&gt;&gt; len(s)<br \/>\n4<\/p>\n<p>&gt;&gt;&gt; p &#061; [&#039;asp&#039;, &#039;php&#039;]<br \/>\n&gt;&gt;&gt; s &#061; [&#039;python&#039;, &#039;java&#039;, p, &#039;scheme&#039;]<br \/>\n#&#039;php&#039;\u53ef\u4ee5\u5199p[1]\u6216\u8005s[2][1]<\/p>\n<h5 id=\"%E7%A9%BA\">\u7a7a<\/h5>\n<p>list\u4e2d\u4e00\u4e2a\u5143\u7d20\u4e5f\u6ca1\u6709 \u00a0 \u5c31\u662f\u4e00\u4e2a\u7a7a\u7684list \u00a0 \u00a0\u957f\u5ea6\u4e3a0<\/p>\n<p>&gt;&gt;&gt; L &#061; []<br \/>\n&gt;&gt;&gt; len(L)<br \/>\n0<\/p>\n<h4 id=\"tuple\">tuple<\/h4>\n<p>\u53e6\u4e00\u79cd\u6709\u5e8f\u5217\u8868\u53eb\u00a0<span style=\"color:#6eaad7\">\u5143\u7ec4&#xff1a;tuple<\/span><\/p>\n<p>tuple\u548clist\u975e\u5e38\u7c7b\u4f3c \u00a0 \u4f46tuple\u4e00\u65e6\u521d\u59cb\u5316\u5c31<span style=\"color:#ed7976\">\u4e0d\u80fd\u4fee\u6539<\/span><\/p>\n<p>&gt;&gt;&gt; classmates &#061; (&#039;Michael&#039;, &#039;Bob&#039;, &#039;Tracy&#039;)<br \/>\n#\u5217\u51fa\u540c\u5b66\u540d\u5b57<\/p>\n<p>classmates\u8fd9\u4e2atuple\u4e0d\u80fd\u53d8 \u00a0 \u5b83\u4e5f<span style=\"color:#ed7976\">\u6ca1\u6709append() \u00a0insert()<\/span><\/p>\n<p>\u5176\u4ed6\u83b7\u53d6\u5143\u7d20\u7684\u65b9\u6cd5\u548clist\u662f\u4e00\u6837\u7684 \u00a0\u4f60\u53ef\u4ee5\u6b63\u5e38\u5730\u4f7f\u7528classmates[0]<font face=\"-apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun\">\u00a0<\/font>classmates[-1]\u4f46<span style=\"color:#ed7976\">\u4e0d\u80fd\u8d4b\u503c<\/span>\u6210\u53e6\u5916\u7684\u5143\u7d20<\/p>\n<p>\u4e0d\u53ef\u53d8\u7684tuple\u6709\u4ec0\u4e48\u610f\u4e49&#xff1f;<\/p>\n<p>\u56e0\u4e3atuple\u4e0d\u53ef\u53d8 \u00a0\u6240\u4ee5\u4ee3\u7801\u66f4\u5b89\u5168 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0 \u5982\u679c\u53ef\u80fd \u00a0\u80fd\u7528tuple\u4ee3\u66fflist\u5c31\u5c3d\u91cf\u7528tuple<\/p>\n<h5 id=\"%E5%AE%9A%E4%B9%89%20tuple\">\u5b9a\u4e49 tuple<\/h5>\n<p>\u5728\u5b9a\u4e49\u65f6\u00a0 \u00a0 \u00a0tuple\u7684\u5143\u7d20 \u00a0<span style=\"color:#ed7976\">\u5fc5\u987b\u88ab\u786e\u5b9a\u4e0b\u6765<\/span><\/p>\n<p>&gt;&gt;&gt; t &#061; (1, 2)<br \/>\n&gt;&gt;&gt; t<br \/>\n(1, 2)<\/p>\n<h5 id=\"%E7%A9%BA%20()\">\u7a7a ()<\/h5>\n<p>\u5982\u679c\u8981\u5b9a\u4e49\u4e00\u4e2a\u7a7a\u7684tuple \u00a0 \u00a0 \u00a0 \u53ef\u4ee5\u5199\u6210()<\/p>\n<p>&gt;&gt;&gt; t &#061; ()<br \/>\n&gt;&gt;&gt; t<br \/>\n()<\/p>\n<h5 id=\"%E4%B8%80%E4%B8%AA%E5%85%83%E7%B4%A0\">\u4e00\u4e2a\u5143\u7d20<\/h5>\n<p>\u5b9a\u4e49\u4e00\u4e2a\u53ea\u67091\u4e2a\u5143\u7d20\u7684tuple<\/p>\n<p>&gt;&gt;&gt; t &#061; (1)<br \/>\n&gt;&gt;&gt; t<br \/>\n1<\/p>\n<p><span style=\"color:#ed7976\">\u6ce8\u610f: \u5b9a\u4e49\u7684\u4e0d\u662ftuple \u00a0 \u00a0 \u00a0 \u00a0\u662f1\u8fd9\u4e2a\u6570&#xff01;<\/span><\/p>\n<p>\u56e0\u4e3a\u62ec\u53f7\u00a0()\u00a0\u65e2\u53ef\u4ee5\u8868\u793a<span style=\"color:#6eaad7\">tuple<\/span>&#xff0c;\u53c8\u53ef\u8868\u793a<span style=\"color:#6eaad7\">\u6570\u5b66\u516c\u5f0f\u4e2d\u7684\u5c0f\u62ec\u53f7<\/span><\/p>\n<p>\u56e0\u6b64 \u00a0 \u00a0Python\u89c4\u5b9a \u00a0 \u8fd9\u79cd\u60c5\u51b5\u4e0b \u00a0 \u6309\u5c0f\u62ec\u53f7\u8fdb\u884c\u8ba1\u7b97 \u00a0 \u00a0\u00a0\u8ba1\u7b97\u7ed3\u679c\u81ea\u7136\u662f1<\/p>\n<p>\u53ea\u67091\u4e2a\u5143\u7d20 \u00a0 tuple \u00a0 \u5b9a\u4e49 \u00a0 \u00a0 \u5fc5\u987b\u52a0\u4e00\u4e2a\u9017\u53f7 \u00a0,<\/p>\n<p>&gt;&gt;&gt; t &#061; (1,)<br \/>\n&gt;&gt;&gt; t<br \/>\n(1,)<br \/>\n#Python\u5728\u663e\u793a\u53ea\u67091\u4e2a\u5143\u7d20\u7684tuple\u65f6  \u4e5f\u4f1a\u52a0\u4e00\u4e2a\u9017\u53f7, \u4ee5\u514d\u8bef\u89e3\u6210\u6570\u5b66\u8ba1\u7b97\u610f\u4e49\u4e0a\u7684\u62ec\u53f7<\/p>\n<h5 id=\"%E7%89%B9%E6%AE%8A%20%E2%80%9C%E5%8F%AF%E5%8F%98%E7%9A%84%E2%80%9D%20tuple\">\u7279\u6b8a \u201c\u53ef\u53d8\u7684\u201d tuple<\/h5>\n<p>&gt;&gt;&gt; t &#061; (&#039;a&#039;, &#039;b&#039;, [&#039;A&#039;, &#039;B&#039;])<br \/>\n&gt;&gt;&gt; t[2][0] &#061; &#039;X&#039;<br \/>\n&gt;&gt;&gt; t[2][1] &#061; &#039;Y&#039;<br \/>\n&gt;&gt;&gt; t<br \/>\n(&#039;a&#039;, &#039;b&#039;, [&#039;X&#039;, &#039;Y&#039;])<\/p>\n<p>tuple\u5b9a\u4e49 \u00a0 \u00a03\u4e2a\u5143\u7d20 \u00a0 \u5206\u522b\u662f&#039;a&#039;<font face=\"-apple-system, SF UI Text, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei, WenQuanYi Micro Hei, sans-serif, SimHei, SimSun\">\u00a0 \u00a0<\/font>&#039;b&#039; \u548c\u00a0\u4e00\u4e2alist<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"566\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b07a9e78.png\" width=\"764\" \/><\/p>\n<p>list\u7684\u5143\u7d20&#039;A&#039;\u548c&#039;B&#039;\u00a0\u4fee\u6539\u4e3a&#039; X&#039;\u548c&#039;Y&#039;\u00a0tuple\u53d8\u4e3a&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"564\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022511-6a7d2b07c421d.png\" width=\"764\" \/><\/p>\n<p>\u8868\u9762\u4e0a\u770b&#xff0c;tuple\u7684\u5143\u7d20\u786e\u5b9e\u53d8\u4e86&#xff0c;\u4f46\u5176\u5b9e\u53d8\u7684\u4e0d\u662ftuple\u7684\u5143\u7d20&#xff0c;\u800c\u662flist\u7684\u5143\u7d20\u3002<\/p>\n<p>tuple\u4e00\u5f00\u59cb\u6307\u5411\u7684list\u5e76\u6ca1\u6709\u6539\u6210\u522b\u7684list&#xff0c;\u6240\u4ee5&#xff0c;tuple\u6240\u8c13\u7684\u201c\u4e0d\u53d8\u201d\u662f\u8bf4&#xff0c;tuple\u7684\u6bcf\u4e2a\u5143\u7d20&#xff0c;\u6307\u5411\u6c38\u8fdc\u4e0d\u53d8\u3002\u5373\u6307\u5411&#039;a&#039;&#xff0c;\u5c31\u4e0d\u80fd\u6539\u6210\u6307\u5411&#039;b&#039;&#xff0c;\u6307\u5411\u4e00\u4e2alist&#xff0c;\u5c31\u4e0d\u80fd\u6539\u6210\u6307\u5411\u5176\u4ed6\u5bf9\u8c61&#xff0c;\u4f46\u6307\u5411\u7684\u8fd9\u4e2alist\u672c\u8eab\u662f\u53ef\u53d8\u7684&#xff01;<\/p>\n<p><span style=\"color:#ed7976\">\u5fc5\u987b\u4fdd\u8bc1tuple\u7684\u6bcf\u4e00\u4e2a\u5143\u7d20\u672c\u8eab\u4e0d\u80fd\u53d8<\/span><\/p>\n<h3 id=\"%E6%9D%A1%E4%BB%B6%E5%88%A4%E6%96%AD\">\u6761\u4ef6\u5224\u65ad<\/h3>\n<p>if &lt;\u6761\u4ef6\u5224\u65ad1&gt;:<br \/>\n\u00a0 \u00a0 &lt;\u6267\u884c1&gt;<br \/>\nelif &lt;\u6761\u4ef6\u5224\u65ad2&gt;:<br \/>\n\u00a0 \u00a0 &lt;\u6267\u884c2&gt;<br \/>\nelif &lt;\u6761\u4ef6\u5224\u65ad3&gt;:<br \/>\n\u00a0 \u00a0 &lt;\u6267\u884c3&gt;<br \/>\nelse:<br \/>\n\u00a0 \u00a0 &lt;\u6267\u884c4&gt;<\/p>\n<p>age &#061; 20<br \/>\nif age &gt;&#061; 6:<br \/>\n    print(&#039;teenager&#039;)<br \/>\nelif age &gt;&#061; 18:<br \/>\n    print(&#039;adult&#039;)<br \/>\nelse:<br \/>\n    print(&#039;kid&#039;)<\/p>\n<h4 id=\"input()\">input()<\/h4>\n<p>input()\u00a0\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u662f\u00a0str<\/p>\n<p>str\u00a0\u4e0d\u80fd\u76f4\u63a5\u548c\u6574\u6570\u6bd4\u8f83 \u00a0 \u00a0\u00a0str\u8f6c\u6362\u6210\u6574\u6570<\/p>\n<p>Python\u63d0\u4f9b\u4e86 \u00a0int()\u51fd\u6570<\/p>\n<p>s &#061; input(&#039;birth: &#039;)<br \/>\nbirth &#061; int(s)<br \/>\nif birth &lt; 2000:<br \/>\n    print(&#039;00\u524d&#039;)<br \/>\nelse:<br \/>\n    print(&#039;00\u540e&#039;)<\/p>\n<h3 id=\"%E6%A8%A1%E5%BC%8F%E5%8C%B9%E9%85%8D\">\u6a21\u5f0f\u5339\u914d<\/h3>\n<p>if \u8bed\u53e5<\/p>\n<p>score &#061; &#039;B&#039;<br \/>\nif score &#061;&#061; &#039;A&#039;:<br \/>\n    print(&#039;score is A.&#039;)<br \/>\nelif score &#061;&#061; &#039;B&#039;:<br \/>\n    print(&#039;score is B.&#039;)<br \/>\nelif score &#061;&#061; &#039;C&#039;:<br \/>\n    print(&#039;score is C.&#039;)<br \/>\nelse:<br \/>\n    print(&#039;invalid score.&#039;)<\/p>\n<h4 id=\"match%20%E8%AF%AD%E5%8F%A5\">match \u8bed\u53e5<\/h4>\n<p>\u5728\u6700\u540e&#xff08;\u4e14\u4ec5\u80fd\u5728\u6700\u540e&#xff09;\u52a0\u4e00\u4e2acase _\u8868\u793a\u201c\u4efb\u610f\u503c\u201d<\/p>\n<p>score &#061; &#039;B&#039;<\/p>\n<p>match score:<br \/>\n    case &#039;A&#039;:<br \/>\n        print(&#039;score is A.&#039;)<br \/>\n    case &#039;B&#039;:<br \/>\n        print(&#039;score is B.&#039;)<br \/>\n    case &#039;C&#039;:<br \/>\n        print(&#039;score is C.&#039;)<br \/>\n    case _: # _\u8868\u793a\u5339\u914d\u5230\u5176\u4ed6\u4efb\u4f55\u60c5\u51b5<br \/>\n        print(&#039;score is ???.&#039;)<\/p>\n<h3 id=\"%E5%A4%8D%E6%9D%82%E5%8C%B9%E9%85%8D\">\u590d\u6742\u5339\u914d<\/h3>\n<p>match\u8bed\u53e5 \u00a0 \u53ef\u5339\u914d \u00a0 <span style=\"color:#ed7976\">\u591a\u4e2a\u503c \u00a0\u5339\u914d\u4e00\u5b9a\u8303\u56f4 \u00a0<\/span><\/p>\n<p>\u5e76\u4e14\u628a\u5339\u914d\u540e\u7684\u503c\u7ed1\u5b9a\u5230\u53d8\u91cf<\/p>\n<p>age &#061; 15<\/p>\n<p>match age:<br \/>\n    case x if x &lt; 10:<br \/>\n        print(f&#039;&lt; 10 years old: {x}&#039;)<br \/>\n    case 10:<br \/>\n        print(&#039;10 years old.&#039;)<br \/>\n    case 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18:<br \/>\n        print(&#039;11~18 years old.&#039;)<br \/>\n    case 19:<br \/>\n        print(&#039;19 years old.&#039;)<br \/>\n    case _:<br \/>\n        print(&#039;not sure.&#039;)<\/p>\n<ul>\n<li>\u00a0\u00a0case x if x &lt; 10 \u00a0\u8868 \u00a0\u00a0age &lt; 10 \u00a0\u6210\u7acb\u65f6\u5339\u914d \u00a0 \u00a0 \u4e14\u8d4b\u503c\u7ed9\u53d8\u91cfx<\/li>\n<li>\u00a0 case 10 \u00a0 \u00a0\u4ec5\u5339\u914d\u5355\u4e2a\u503c<\/li>\n<li>\u00a0\u00a0case 11|12|&#8230;|18\u00a0\u5339\u914d\u591a\u4e2a\u503c \u00a0 \u00a0 \u00a0 \u00a0 \u7528<span style=\"color:#0d0016\">|<\/span>\u5206\u9694<\/li>\n<\/ul>\n<h3 id=\"%E5%8C%B9%E9%85%8D%E5%88%97%E8%A1%A8\" style=\"background-color:transparent\">\u5339\u914d\u5217\u8868<\/h3>\n<p>#\u7528 args &#061; [&#039;gcc&#039;, &#039;hello.c&#039;, &#039;world.c&#039;] \u5b58\u50a8<br \/>\nargs &#061; [&#039;gcc&#039;, &#039;hello.c&#039;, &#039;world.c&#039;]<br \/>\n# args &#061; [&#039;clean&#039;]<br \/>\n# args &#061; [&#039;gcc&#039;]<\/p>\n<p>match args:<br \/>\n    # \u5982\u679c\u4ec5\u51fa\u73b0gcc&#xff0c;\u62a5\u9519:<br \/>\n    case [&#039;gcc&#039;]:<br \/>\n        print(&#039;gcc: missing source file(s).&#039;)<br \/>\n    # \u51fa\u73b0gcc&#xff0c;\u4e14\u81f3\u5c11\u6307\u5b9a\u4e86\u4e00\u4e2a\u6587\u4ef6:<br \/>\n    case [&#039;gcc&#039;, file1, *files]:<br \/>\n        print(&#039;gcc compile: &#039; &#043; file1 &#043; &#039;, &#039; &#043; &#039;, &#039;.join(files))<br \/>\n    # \u4ec5\u51fa\u73b0clean:<br \/>\n    case [&#039;clean&#039;]:<br \/>\n        print(&#039;clean&#039;)<br \/>\n    case _:<br \/>\n        print(&#039;invalid command.&#039;)<\/p>\n<ul>\n<li>case [&#039;gcc&#039;] \u00a0\u00a0\u8868\u793a\u5217\u8868\u4ec5\u6709&#039;gcc&#039;\u4e00\u4e2a\u5b57\u7b26\u4e32 \u00a0 \u00a0\u6ca1\u6709\u6307\u5b9a\u6587\u4ef6\u540d \u00a0 \u00a0 \u62a5\u9519<\/li>\n<li>case [&#039;gcc&#039;, file1, *files] \u00a0 \u8868\u793a\u5217\u8868\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e32\u662f&#039;gcc&#039; \u00a0\u7b2c\u4e8c\u4e2a\u5b57\u7b26\u4e32\u7ed1\u5b9a\u5230\u53d8\u91cffile1 \u00a0\u00a0\u540e\u9762\u7684\u4efb\u610f\u4e2a\u5b57\u7b26\u4e32\u7ed1\u5b9a\u5230*files \u00a0\u00a0\u5b9e\u9645\u4e0a\u8868\u793a\u81f3\u5c11\u6307\u5b9a\u4e00\u4e2a\u6587\u4ef6<\/li>\n<li>case [&#039;clean&#039;] \u00a0\u00a0\u8868\u793a\u5217\u8868\u4ec5\u6709&#039;clean&#039;\u4e00\u4e2a\u5b57\u7b26\u4e32<\/li>\n<li>case _ \u00a0\u00a0\u8868\u793a\u5176\u4ed6\u6240\u6709\u60c5\u51b5<\/li>\n<\/ul>\n<h3 id=\"%E5%BE%AA%E7%8E%AF\">\u5faa\u73af<\/h3>\n<h4 id=\"for%20...%20in%20....%20%E5%BE%AA%E7%8E%AF\">for &#8230; in &#8230;. \u5faa\u73af<\/h4>\n<p>\u8ba1\u7b97 1 &#8211; 10 \u6574\u6570\u4e4b\u548c&#xff1a;<\/p>\n<p>sum &#061; 0<br \/>\nfor x in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]:<br \/>\n    sum &#061; sum &#043; x<br \/>\nprint(sum)<\/p>\n<h5 id=\"range(%EF%BC%89%E5%87%BD%E6%95%B0\">range(&#xff09;\u51fd\u6570<\/h5>\n<p>range()\u51fd\u6570 \u00a0 \u53ef \u751f\u6210\u4e00\u4e2a \u6574\u6570\u5e8f\u5217 \u00a0 \u00a0\u518d\u901a\u8fc7\u00a0list()\u51fd\u6570 \u8f6c\u6362\u4e3a list<\/p>\n<p>\u6bd4\u5982\u00a0range(5)\u00a0\u751f\u6210\u7684 \u5e8f\u5217 \u662f\u4ece 0 \u5f00\u59cb \u5c0f\u4e8e5 \u7684 \u6574\u6570<\/p>\n<p>&gt;&gt;&gt; list(range(5))<br \/>\n[0, 1, 2, 3, 4]<\/p>\n<p>\u8ba1\u7b97 1 &#8211; 100 \u6574\u6570\u4e4b\u548c&#xff1a;<\/p>\n<p>sum &#061; 0<br \/>\nfor x in range(101):<br \/>\n    sum &#061; sum &#043; x<br \/>\nprint(sum)<\/p>\n<h4 id=\"while%20%E5%BE%AA%E7%8E%AF\">while \u5faa\u73af<\/h4>\n<p>\u6761\u4ef6\u6ee1\u8db3 \u00a0 \u4e0d\u65ad\u5faa\u73af<\/p>\n<p>\u6761\u4ef6\u4e0d\u6ee1\u8db3 \u00a0\u9000\u51fa\u5faa\u73af<\/p>\n<p>100\u4ee5\u5185\u6240\u6709\u5947\u6570\u4e4b\u548c:<\/p>\n<p>sum &#061; 0<br \/>\nn &#061; 99<br \/>\nwhile n &gt; 0:<br \/>\n    sum &#061; sum &#043; n<br \/>\n    n &#061; n &#8211; 2<br \/>\nprint(sum)<\/p>\n<h4 id=\"break\">break<\/h4>\n<p>\u53ef \u63d0\u524d \u9000\u51fa\u5faa\u73af<\/p>\n<p>n &#061; 1<br \/>\nwhile n &lt;&#061; 100:<br \/>\n    if n &gt; 10: # \u5f53n &#061; 11\u65f6&#xff0c;\u6761\u4ef6\u6ee1\u8db3&#xff0c;\u6267\u884cbreak\u8bed\u53e5<br \/>\n        break # break\u8bed\u53e5\u4f1a\u7ed3\u675f\u5f53\u524d\u5faa\u73af<br \/>\n    print(n)<br \/>\n    n &#061; n &#043; 1<br \/>\nprint(&#039;END&#039;)<\/p>\n<h4 id=\"continue\">continue<\/h4>\n<p>\u8df3\u8fc7 \u5f53\u524d\u8fd9\u6b21\u5faa\u73af \u00a0 \u76f4\u63a5\u5f00\u59cb \u00a0\u4e0b\u4e00\u6b21\u5faa\u73af<\/p>\n<p>n &#061; 0<br \/>\nwhile n &lt; 10:<br \/>\n    n &#061; n &#043; 1<br \/>\n    if n % 2 &#061;&#061; 0: # \u5982\u679cn\u662f\u5076\u6570&#xff0c;\u6267\u884ccontinue\u8bed\u53e5<br \/>\n        continue # continue\u8bed\u53e5\u4f1a\u76f4\u63a5\u7ee7\u7eed\u4e0b\u4e00\u8f6e\u5faa\u73af&#xff0c;\u540e\u7eed\u7684print()\u8bed\u53e5\u4e0d\u4f1a\u6267\u884c<br \/>\n    print(n)<\/p>\n<h3 id=\"dict%20%E5%92%8C%20set\" style=\"background-color:transparent\">dict \u548c set<\/h3>\n<h4 id=\"dict\">dict<\/h4>\n<p>Python\u5185\u7f6e\u4e86\u5b57\u5178&#xff1a;dict\u7684\u652f\u6301 \u00a0 \u00a0dict\u5168\u79f0 dictionary \u00a0 \u5728\u5176\u4ed6\u8bed\u8a00\u4e2d\u79f0 map \u00a0\u4f7f\u7528\u952e-\u503c&#xff08;key-value&#xff09;\u5b58\u50a8 \u00a0\u5177\u6709\u6781\u5feb\u7684\u67e5\u627e\u901f\u5ea6<\/p>\n<p>&gt;&gt;&gt; d &#061; {&#039;Michael&#039;: 95, &#039;Bob&#039;: 75, &#039;Tracy&#039;: 85}<br \/>\n&gt;&gt;&gt; d[&#039;Michael&#039;]<br \/>\n95<\/p>\n<p>key \u653e\u5165<\/p>\n<p>&gt;&gt;&gt; d[&#039;Adam&#039;] &#061; 67<br \/>\n&gt;&gt;&gt; d[&#039;Adam&#039;]<br \/>\n67<\/p>\n<p>\u4e00\u4e2a key \u5bf9\u5e94 \u4e00\u4e2a value \u00a0 \u00a0 \u00a0 \u00a0 &#8212;&#8211;&gt;\u00a0 \u00a0 \u00a0 \u00a0 \u540e\u9762\u7684\u503c \u00a0\u4f1a\u628a \u524d\u9762\u7684\u503c \u51b2\u6389<\/p>\n<p>\u5982\u679c key \u4e0d\u5b58\u5728 \u00a0 \u00a0dict \u00a0\u62a5\u9519<\/p>\n<p>\u907f\u514dkey\u4e0d\u5b58\u5728\u65b9\u6cd5&#xff1a;<\/p>\n<p><span style=\"color:#6eaad7\">\u00a0in \u00a0\u5224\u65adkey \u662f\u5426\u5b58\u5728<\/span><\/p>\n<p>&gt;&gt;&gt; &#039;Thomas&#039; in d<br \/>\nFalse<\/p>\n<p><span style=\"color:#6eaad7\">get() \u65b9\u6cd5<\/span><\/p>\n<p>\u5982\u679ckey\u4e0d\u5b58\u5728 \u00a0 \u00a0 \u53ef\u4ee5\u8fd4\u56deNone \u00a0\u6216 \u00a0\u81ea\u5df1\u6307\u5b9a value&#xff1a;<\/p>\n<p>&gt;&gt;&gt; d.get(&#039;Thomas&#039;)<br \/>\n&gt;&gt;&gt; d.get(&#039;Thomas&#039;, -1)<br \/>\n-1<\/p>\n<p><span style=\"color:#ed7976\">\u6ce8\u610f&#xff1a;\u8fd4\u56deNone \u00a0Python\u4ea4\u4e92\u73af\u5883 \u4e0d\u663e\u793a \u7ed3\u679c<\/span><\/p>\n<p><span style=\"color:#6eaad7\">pop(key) \u65b9\u6cd5<\/span> \u00a0 \u00a0\u5220\u9664\u4e00\u4e2akey<\/p>\n<p>&gt;&gt;&gt; d.pop(&#039;Bob&#039;)<br \/>\n75<br \/>\n&gt;&gt;&gt; d<br \/>\n{&#039;Michael&#039;: 95, &#039;Tracy&#039;: 85}<\/p>\n<p><span style=\"color:#ed7976\">\u5bf9\u5e94\u7684 value \u4e5f\u4f1a\u4ece dict \u4e2d\u5220\u9664<\/span><\/p>\n<h5 id=\"list%20%E5%92%8C%20dict%C2%A0%E6%AF%94%E8%BE%83\">list \u548c dict\u00a0\u6bd4\u8f83<\/h5>\n<p>dict<\/p>\n<li>\u67e5\u627e\u548c\u63d2\u5165\u7684\u901f\u5ea6\u6781\u5feb \u00a0 \u4e0d\u4f1a\u968f\u7740key\u7684\u589e\u52a0\u800c\u53d8\u6162<\/li>\n<li>\u9700\u8981\u5360\u7528\u5927\u91cf\u7684\u5185\u5b58 \u00a0 \u5185\u5b58\u6d6a\u8d39\u591a<\/li>\n<p>dict\u7684key\u5fc5\u987b\u662f<span style=\"color:#ed7976\">\u4e0d\u53ef\u53d8\u5bf9\u8c61<\/span><\/p>\n<p>list<\/p>\n<li>\u67e5\u627e\u548c\u63d2\u5165\u7684\u65f6\u95f4\u968f\u7740\u5143\u7d20\u7684\u589e\u52a0\u800c\u589e\u52a0<\/li>\n<li>\u5360\u7528\u7a7a\u95f4\u5c0f \u00a0\u6d6a\u8d39\u5185\u5b58\u5f88\u5c11<\/li>\n<h4 id=\"set\">set<\/h4>\n<p>set \u548c dict \u7c7b\u4f3c \u00a0 \u662f\u4e00\u7ec4key\u7684\u96c6\u5408 \u00a0 \u4e0d\u5b58\u50a8value<\/p>\n<p>key \u4e0d\u80fd\u91cd\u590d \u00a0 \u5728 set \u4e2d \u6ca1\u6709\u91cd\u590d\u7684 key<\/p>\n<p>&gt;&gt;&gt; s &#061; {1, 2, 3}<br \/>\n&gt;&gt;&gt; s<br \/>\n{1, 2, 3}<\/p>\n<p>&gt;&gt;&gt; s &#061; set([1, 2, 3])<br \/>\n&gt;&gt;&gt; s<br \/>\n{1, 2, 3}<\/p>\n<p>&gt;&gt;&gt; s &#061; {1, 1, 2, 2, 3, 3}<br \/>\n&gt;&gt;&gt; s<br \/>\n{1, 2, 3}<\/p>\n<h5 id=\"add(key)%20%C2%A0%E6%B7%BB%E5%8A%A0%20%E5%85%83%E7%B4%A0%20%E5%8F%AF%E9%87%8D%E5%A4%8D%20%E6%B7%BB%E5%8A%A0(%E6%97%A0%E6%95%88%E6%9E%9C)\">add(key) \u00a0\u6dfb\u52a0 \u5143\u7d20 \u53ef\u91cd\u590d \u6dfb\u52a0(\u65e0\u6548\u679c)<\/h5>\n<p>&gt;&gt;&gt; s.add(4)<br \/>\n&gt;&gt;&gt; s<br \/>\n{1, 2, 3, 4}<br \/>\n&gt;&gt;&gt; s.add(4)<br \/>\n&gt;&gt;&gt; s<br \/>\n{1, 2, 3, 4}<\/p>\n<h5 id=\"remove(key)%20%C2%A0%E5%88%A0%E9%99%A4%20%E5%85%83%E7%B4%A0\">remove(key) \u00a0\u5220\u9664 \u5143\u7d20<\/h5>\n<p>&gt;&gt;&gt; s.remove(4)<br \/>\n&gt;&gt;&gt; s<br \/>\n{1, 2, 3}<\/p>\n<p>\u4ea4\u96c6 \u00a0 \u00a0\u5e76\u96c6<\/p>\n<p>&gt;&gt;&gt; s1 &#061; {1, 2, 3}<br \/>\n&gt;&gt;&gt; s2 &#061; {2, 3, 4}<br \/>\n&gt;&gt;&gt; s1 &amp; s2<br \/>\n{2, 3}<br \/>\n&gt;&gt;&gt; s1 | s2<br \/>\n{1, 2, 3, 4}<\/p>\n<h5 id=\"set%20%E5%92%8C%20dict%20%E6%AF%94%E8%BE%83\">set \u548c dict \u6bd4\u8f83<\/h5>\n<p>\u552f\u4e00\u533a\u522b\u4ec5\u5728\u4e8e \u6ca1\u6709 \u5b58\u50a8\u5bf9\u5e94\u7684value \u00a0<\/p>\n<p>set\u539f\u7406 \u548c dict \u4e00\u6837 \u00a0 \u00a0 \u4e0d\u53ef\u4ee5\u653e\u5165\u53ef\u53d8\u5bf9\u8c61 \u00a0\u56e0\u4e3a\u65e0\u6cd5\u5224\u65ad\u4e24\u4e2a\u53ef\u53d8\u5bf9\u8c61\u662f\u5426\u76f8\u7b49\u00a0<\/p>\n<h4 id=\"%E4%B8%8D%E5%8F%AF%E5%8F%98%E5%AF%B9%E8%B1%A1\">\u4e0d\u53ef\u53d8\u5bf9\u8c61<\/h4>\n<p>list \u53ef\u53d8\u5bf9\u8c61 \u00a0 \u00a0 \u00a0 \u00a0 str \u4e0d\u53d8\u5bf9\u8c61<\/p>\n<p>&gt;&gt;&gt; a &#061; &#039;abc&#039;<br \/>\n&gt;&gt;&gt; a.replace(&#039;a&#039;, &#039;A&#039;)<br \/>\n&#039;Abc&#039;<br \/>\n&gt;&gt;&gt; a<br \/>\n&#039;abc&#039;<\/p>\n<p>&gt;&gt;&gt; a &#061; [&#039;c&#039;, &#039;b&#039;, &#039;a&#039;]<br \/>\n&gt;&gt;&gt; a.sort()<br \/>\n&gt;&gt;&gt; a<br \/>\n[&#039;a&#039;, &#039;b&#039;, &#039;c&#039;]<\/p>\n<h5 id=\"replace()%20%C2%A0%E6%96%B9%E6%B3%95\">replace() \u00a0\u65b9\u6cd5<\/h5>\n<p>&gt;&gt;&gt; a &#061; &#039;abc&#039;<br \/>\n&gt;&gt;&gt; b &#061; a.replace(&#039;a&#039;, &#039;A&#039;)<br \/>\n&gt;&gt;&gt; b<br \/>\n&#039;Abc&#039;<br \/>\n&gt;&gt;&gt; a<br \/>\n&#039;abc&#039;<\/p>\n<p><span style=\"color:#ed7976\">a\u00a0\u662f \u53d8\u91cf \u00a0 \u00a0 &#039;abc&#039;\u662f \u5b57\u7b26\u4e32\u5bf9\u8c61<\/span><\/p>\n<p><font face=\"monospace\">a &#8212;&gt; &#039;abc&#039;<\/font><\/p>\n<p>a.replace(&#039;a&#039;, &#039;A&#039;) \u8c03\u7528 \u65b9\u6cd5replace\u00a0\u662f\u4f5c\u7528\u5728 \u5b57\u7b26\u4e32\u5bf9\u8c61&#039;abc&#039;\u00a0\u4e0a\u00a0\u6ca1\u6709\u6539\u53d8\u5b57\u7b26\u4e32&#039;abc&#039;\u7684\u5185\u5bb9<\/p>\n<p>replace\u65b9\u6cd5 \u00a0\u521b\u5efa \u4e00\u4e2a\u65b0 \u5b57\u7b26\u4e32&#039;Abc&#039;\u00a0\u5e76 \u8fd4\u56de \u00a0<\/p>\n<p>a &#8212;&gt; &#039;abc&#039;<\/p>\n<p>b&#8212;-&gt; &#039;Abc&#039;<\/p>\n<p>\u4e0d\u53ef\u53d8\u5bf9\u8c61 \u8c03\u7528\u81ea\u8eab\u65b9\u6cd5 \u4e0d\u4f1a\u4fee\u6539 \u539f\u5bf9\u8c61 \u800c\u662f\u8fd4\u56de\u65b0\u5bf9\u8c61 \u539f\u5bf9\u8c61\u59cb\u7ec8\u4fdd\u6301\u4e0d\u53d8<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u7a0b\u5e8fPython\u4ea4\u4e92\u6a21\u5f0f\u6572\u4e0b\u547d\u4ee4&#xff1a;python3   \u63d0\u793a\u7b26&#xff1a;&gt;&gt;&gt;  \u8f93\u5165exit() \u5e76\u56de\u8f66 \u9000\u51fa python\u4ea4\u4e92\u6a21\u5f0f \u56de\u5230 \u547d\u4ee4\u884c\u6a21\u5f0f.py \u6587\u4ef6 \u53ea\u80fd\u5728 \u547d\u4ee4\u884c\u6a21\u5f0f python3 hello.py &#8212;-&gt; \u8def\u5f84\u5728 Python \u4e2d\u547d\u4ee4\u884c\u6a21\u5f0f\u548cPython\u4ea4\u4e92\u6a21\u5f0fPython\u4ea4\u4e92\u5f0f\u73af\u5883\u4e0b\u8f93\u51fa&gt;&gt;&gt; print(hello,world,relaxing atmosphere,working atmosphere)<br \/>\n# hel<\/p>\n","protected":false},"author":2,"featured_media":93830,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,190],"topic":[],"class_list":["post-93847","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python \u57fa\u7840\u77e5\u8bc6 - \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\/93847.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python \u57fa\u7840\u77e5\u8bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Python\u7a0b\u5e8fPython\u4ea4\u4e92\u6a21\u5f0f\u6572\u4e0b\u547d\u4ee4&#xff1a;python3  \u63d0\u793a\u7b26&#xff1a;&gt;&gt;&gt; \u8f93\u5165exit() \u5e76\u56de\u8f66 \u9000\u51fa python\u4ea4\u4e92\u6a21\u5f0f \u56de\u5230 \u547d\u4ee4\u884c\u6a21\u5f0f.py \u6587\u4ef6 \u53ea\u80fd\u5728 \u547d\u4ee4\u884c\u6a21\u5f0f python3 hello.py ----&gt; \u8def\u5f84\u5728 Python \u4e2d\u547d\u4ee4\u884c\u6a21\u5f0f\u548cPython\u4ea4\u4e92\u6a21\u5f0fPython\u4ea4\u4e92\u5f0f\u73af\u5883\u4e0b\u8f93\u51fa&gt;&gt;&gt; print(hello,world,relaxing atmosphere,working atmosphere) # hel\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/93847.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-13T02:25:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022507-6a7d2b036c009.png\" \/>\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=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/93847.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/93847.html\",\"name\":\"Python \u57fa\u7840\u77e5\u8bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-13T02:25:12+00:00\",\"dateModified\":\"2026-08-13T02:25:12+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/93847.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/93847.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/93847.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python \u57fa\u7840\u77e5\u8bc6\"}]},{\"@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 \u57fa\u7840\u77e5\u8bc6 - \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\/93847.html","og_locale":"zh_CN","og_type":"article","og_title":"Python \u57fa\u7840\u77e5\u8bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Python\u7a0b\u5e8fPython\u4ea4\u4e92\u6a21\u5f0f\u6572\u4e0b\u547d\u4ee4&#xff1a;python3  \u63d0\u793a\u7b26&#xff1a;&gt;&gt;&gt; \u8f93\u5165exit() \u5e76\u56de\u8f66 \u9000\u51fa python\u4ea4\u4e92\u6a21\u5f0f \u56de\u5230 \u547d\u4ee4\u884c\u6a21\u5f0f.py \u6587\u4ef6 \u53ea\u80fd\u5728 \u547d\u4ee4\u884c\u6a21\u5f0f python3 hello.py ----&gt; \u8def\u5f84\u5728 Python \u4e2d\u547d\u4ee4\u884c\u6a21\u5f0f\u548cPython\u4ea4\u4e92\u6a21\u5f0fPython\u4ea4\u4e92\u5f0f\u73af\u5883\u4e0b\u8f93\u51fa&gt;&gt;&gt; print(hello,world,relaxing atmosphere,working atmosphere) # hel","og_url":"https:\/\/www.wsisp.com\/helps\/93847.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-13T02:25:12+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260813022507-6a7d2b036c009.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/93847.html","url":"https:\/\/www.wsisp.com\/helps\/93847.html","name":"Python \u57fa\u7840\u77e5\u8bc6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-13T02:25:12+00:00","dateModified":"2026-08-13T02:25:12+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/93847.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/93847.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/93847.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python \u57fa\u7840\u77e5\u8bc6"}]},{"@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\/93847","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=93847"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/93847\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/93830"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=93847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=93847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=93847"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=93847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}