{"id":205263,"date":"2025-05-29T10:25:22","date_gmt":"2025-05-29T02:25:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205263\/"},"modified":"2025-05-29T10:25:22","modified_gmt":"2025-05-29T02:25:22","slug":"%e6%97%a5%e5%8f%98%e9%87%8f%e5%92%8c%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b-%e5%a4%a9%e8%9f%92","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205263\/","title":{"rendered":"\u65e5\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b | \u5929\u87d2"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u65e5\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b | \u5929\u87d2<\/h1>\n<p>\u76ee\u524d\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u5173\u4e8e<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u7684\u6587\u7ae0\u4e86\uff0c\u81ea\u5df1\u5728\u521d\u6b21\u9605\u8bfb\u8fd9\u4e9b\u6587\u7ae0\u4e2d\uff0c\u4e5f\u89c1\u8bc6\u5230\u4e86\u5f88\u591a\u5b66\u4e60\u601d\u8def\uff1b\u90a3\u4e48\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u65e5\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b | \u5929\u87d2\u300b<\/span>\uff0c\u4e5f\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\uff0c\u5982\u679c\u9605\u8bfb\u5b8c\u540e\u771f\u7684\u5bf9\u4f60\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6709\u5e2e\u52a9\uff0c\u6b22\u8fce\u52a8\u52a8\u624b\u6307\uff0c\u8bc4\u8bba\u7559\u8a00\u5e76\u5206\u4eab~<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241127\/17327016616746eddd5bff4.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u7b2c 5 \u5929\uff1a\u8bc4\u8bba\u3001\u8f6c\u4e49\u5e8f\u5217\u548c\u6253\u5370\u58f0\u660e | 100 \u5929 python<\/strong><\/p>\n<p>python \u7f16\u7a0b\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\u975e\u5e38\u76f4\u89c2\uff0c\u5b66\u4e60\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u7684\u6982\u5ff5\u662f\u57fa\u7840\u3002\u672c\u535a\u5ba2\u5c06\u5f15\u5bfc\u60a8\u4e86\u89e3\u8fd9\u4e9b\u8981\u70b9\uff0c\u4e3a\u521d\u5b66\u8005\u63d0\u4f9b\u4e00\u79cd\u7ed3\u6784\u5316\u7684\u65b9\u6cd5\u6765\u7406\u89e3 python \u7f16\u7a0b\u4e2d\u7684\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u3002\u8ba9\u6211\u4eec\u5f00\u59cb\u5427\uff01<\/p>\n<hr>\n<p>\u5728 python \u4e2d\uff0c\u53d8\u91cf\u5c31\u50cf\u53a8\u623f\u91cc\u7684\u5bb9\u5668\u3002\u6b63\u5982\u60a8\u4f7f\u7528\u4e0d\u540c\u7684\u5bb9\u5668\u6765\u5b58\u50a8\u5927\u7c73\u3001\u6241\u8c46\u3001\u9762\u7c89\u751a\u81f3\u6db2\u4f53\u4e00\u6837\uff0cpython \u53d8\u91cf\u4e5f\u5728\u7a0b\u5e8f\u4e2d\u5b58\u50a8\u6570\u636e\u3002\u8fd9\u4e9b\u5bb9\u5668\u53ef\u4ee5\u4fdd\u5b58\u4efb\u4f55\u6570\u636e\uff0c\u4f8b\u5982\u6570\u5b57\u3001\u6587\u672c\u548c\u5176\u4ed6\u503c\uff0c\u8fd9\u4f7f\u5f97\u5b83\u4eec\u5bf9\u4e8e\u5904\u7406\u548c\u64cd\u4f5c\u4fe1\u606f\u81f3\u5173\u91cd\u8981\u3002<\/p>\n<p>\u60f3\u8c61\u4e00\u4e0b\uff0c\u60a8\u6709\u4e00\u4e2a\u6700\u521d\u88c5\u6709\u5927\u7c73\u7684\u5bb9\u5668\uff0c\u7136\u540e\u60a8\u51b3\u5b9a\u7528\u6241\u8c46\u4ee3\u66ff\u5b83\u3002\u7c7b\u4f3c\u5730\uff0c\u5728 python \u4e2d\uff0c\u60a8\u53ef\u4ee5\u91cd\u65b0\u5206\u914d\u53d8\u91cf\u6765\u4fdd\u5b58\u4e0d\u540c\u7684\u503c\u3002<\/p>\n<p>\u5728 python \u4e2d\u521b\u5efa\u53d8\u91cf\u975e\u5e38\u7b80\u5355\u3002\u53ea\u9700\u4f7f\u7528 = \u8fd0\u7b97\u7b26\u5c06\u503c\u5206\u914d\u7ed9\u53d8\u91cf\u540d\u79f0\uff0c\u5373\u53ef\u5c06\u8be5\u503c\u653e\u5165\u5185\u5b58\u4e2d\u3002<\/p>\n<pre>a = 1  # stores the integer 1 in the variable 'a'\nprint(a)  # outputs 1\n<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0ca\u662f\u6211\u4eec\u7684\u53d8\u91cf\u540d\uff0c\u5b83\u5f53\u524d\u7684\u503c\u662f1\u3002\u901a\u8fc7\u4f7f\u7528print(a)\uff0c\u6211\u4eec\u6307\u793apython\u663e\u793aa\u7684\u503c\uff0c\u8be5\u503c\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff08\u5177\u4f53\u6765\u8bf4\uff0c\u5728ram\u4e2d\uff09\u3002 <\/p>\n<p>\u53d8\u91cf\u5141\u8bb8\u6211\u4eec\u4ee5\u7075\u6d3b\u7684\u65b9\u5f0f\u5f15\u7528\u6570\u636e\u3002\u6211\u4eec\u4e0d\u662f\u5bf9\u6570\u5b57\u6216\u6587\u672c\u8fdb\u884c\u786c\u7f16\u7801\uff0c\u800c\u662f\u5c06\u5176\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\uff0c\u4f7f\u6211\u4eec\u80fd\u591f\u8f7b\u677e\u5730\u64cd\u7eb5\u4fe1\u606f\u3002\u8fd9\u79cd\u65b9\u6cd5\u5728\u590d\u6742\u7684\u64cd\u4f5c\u4e2d\u7279\u522b\u6709\u7528\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u7b80\u5355\u5730\u8c03\u7528\u53d8\u91cf\u540d\u79f0\u6765\u8c03\u7528\u5b58\u50a8\u7684\u6570\u636e\uff0c\u800c\u4e0d\u662f\u6bcf\u6b21\u91cd\u65b0\u8f93\u5165\u503c\u3002<\/p>\n<hr>\n<p>\u6b63\u5982\u5bb9\u5668\u4e2d\u53ef\u4ee5\u653e\u5165\u4e0d\u540c\u7c7b\u578b\u7684\u5185\u5bb9\uff08\u6db2\u4f53\u3001\u56fa\u4f53\u3001\u7c89\u672b\uff09\u4e00\u6837\uff0cpython \u4e5f\u6709\u5404\u79cd\u6570\u636e\u7c7b\u578b\u6765\u5b58\u50a8\u4e0d\u540c\u7c7b\u578b\u7684\u503c\u3002<\/p>\n<p>python\u7684\u4e3b\u8981\u6570\u636e\u7c7b\u578b\u5305\u62ec\uff1a<\/p>\n<ol>\n<li> <strong>\u6574\u6570<\/strong>\uff1a\u6574\u6570\uff08\u4f8b\u5982\uff0c1\u300142\u3001-3\uff09\u3002<\/li>\n<li> <strong>float<\/strong>\uff1a\u5341\u8fdb\u5236\u6570\u5b57\uff08\u4f8b\u5982 3.14\u30012.718\uff09\u3002<\/li>\n<li> <strong>\u5b57\u7b26\u4e32<\/strong>\uff1a\u6587\u672c\uff08\u4f8b\u5982\u201chello\uff0cworld\uff01\u201d\uff09\u3002<\/li>\n<li> <strong>\u5e03\u5c14\u503c<\/strong>\uff1a\u771f\/\u5047\u503c\uff08\u4f8b\u5982\uff0ctrue\u3001false\uff09\u3002<\/li>\n<li> <strong>nonetype<\/strong>\uff1a\u8868\u793a\u6ca1\u6709\u503c\uff08none\uff09\u3002<\/li>\n<li> <strong>\u590d\u6570<\/strong>\uff1a\u5177\u6709\u5b9e\u90e8\u548c\u865a\u90e8\u7684\u6570\u5b57\uff08\u4f8b\u5982\uff0c8 + 2j\uff09\u3002<\/li>\n<\/ol>\n<p>\u6bcf\u79cd\u6570\u636e\u7c7b\u578b\u90fd\u9002\u5408\u7279\u5b9a\u7684\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u6570\u5b66\u8fd0\u7b97\u53ef\u4ee5\u5bf9\u6574\u6570\u548c\u6d6e\u70b9\u6570\u6267\u884c\uff0c\u4f46\u4e0d\u80fd\u76f4\u63a5\u5bf9\u5b57\u7b26\u4e32\u6267\u884c\u3002<\/p>\n<hr>\n<p>\u4ee5\u4e0b\u662f\u6211\u4eec\u5982\u4f55\u5728 python \u4e2d\u4e3a\u53d8\u91cf\u8d4b\u503c\u5e76\u63a2\u7d22\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<pre>a = 1            # integer\nb = true         # boolean\nc = \"python\"     # string\nd = none         # nonetype\ne = 8 + 2j       # complex\nf = 3.14         # float\n\nprint(type(a))   # &lt;class 'int'&gt;\nprint(type(b))   # &lt;class 'bool'&gt;\nprint(type(c))   # &lt;class 'str'&gt;\nprint(type(d))   # &lt;class 'nonetype'&gt;\nprint(type(e))   # &lt;class 'complex'&gt;\nprint(type(f))   # &lt;class 'float'&gt;\n<\/pre>\n<p>\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u770b\u5230\u4e86\u5982\u4f55\u4f7f\u7528 type() \u51fd\u6570\u6765\u663e\u793a\u6bcf\u4e2a\u53d8\u91cf\u7684\u7c7b\u578b\uff0c\u5c55\u793a\u4e86 python \u5728\u5904\u7406\u4e0d\u540c\u6570\u636e\u65b9\u9762\u7684\u591a\u529f\u80fd\u6027\u3002<\/p>\n<hr>\n<p>python \u9650\u5236\u4e0d\u517c\u5bb9\u6570\u636e\u7c7b\u578b\u4e4b\u95f4\u7684\u67d0\u4e9b\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u6dfb\u52a0\u5b57\u7b26\u4e32\u548c\u6574\u6570\u5c06\u5f15\u53d1\u9519\u8bef\uff1a<\/p>\n<pre>a = 123\nb = \"python\"\n\n# this will raise an error\nprint(a + b)  # error: cannot concatenate 'int' and 'str' types\n<\/pre>\n<p>\u4e3a\u4e86\u907f\u514d\u6b64\u7c7b\u9519\u8bef\uff0c\u8bf7\u786e\u4fdd\u64cd\u4f5c\u6d89\u53ca\u517c\u5bb9\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u5982\u679c a = 10 \u548c b = 20\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5b83\u4eec\u76f8\u52a0\u5f97\u5230 a + b = 30\u3002<\/p>\n<hr>\n<p>python \u63d0\u4f9b\u4e86\u591a\u79cd\u5185\u7f6e\u6570\u636e\u7c7b\u578b\uff0c\u6bcf\u79cd\u6570\u636e\u7c7b\u578b\u90fd\u6709\u7279\u5b9a\u7684\u5c5e\u6027\uff1a<\/p>\n<ol>\n<li> <strong>\u6570\u5b57<\/strong>\uff1a\u5305\u62ecint\u3001float\u548ccomplex\u3002<\/li>\n<li> <strong>\u5b57\u7b26\u4e32<\/strong>\uff1a\u7528\u5355\u5f15\u53f7\uff08&#8217;\uff09\u6216\u53cc\u5f15\u53f7\uff08\u201c\uff09\u62ec\u8d77\u6765\u7684\u6587\u672c\u6570\u636e\u3002<\/li>\n<li> <strong>\u5e03\u5c14\u503c<\/strong>\uff1atrue \u6216 false\uff0c\u5728\u6761\u4ef6\u903b\u8f91\u4e2d\u5f88\u6709\u7528\u3002<\/li>\n<li> <strong>\u5e8f\u5217<\/strong>\uff1a\u5305\u62ec\u5217\u8868\u548c\u5143\u7ec4\uff0c\u4ee5\u53ca\u4fdd\u5b58\u6709\u5e8f\u9879\u76ee\u7684\u96c6\u5408\u3002<\/li>\n<\/ol>\n<hr>\n<p><strong>\u5217\u8868<\/strong>\u548c<strong>\u5143\u7ec4<\/strong>\u662f\u53ef\u80fd\u5305\u542b\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u7684\u9879\u76ee\u7684\u96c6\u5408\uff1a<\/p>\n<ul>\n<li> <strong>list<\/strong>\uff1a\u53ef\u53d8\u5e8f\u5217\uff0c\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u66f4\u6539\u3002\u5217\u8868\u5141\u8bb8\u8fdb\u884c\u4fee\u6539\uff0c\u4f8b\u5982\u6dfb\u52a0\u6216\u5220\u9664\u9879\u76ee\u3002 <\/li>\n<\/ul>\n<pre>  my_list = [1, 2, \"apple\", 3.5]  # list with mixed data types\n  my_list.append(\"banana\")  # adding a new item to the list\n  print(my_list)\n<\/pre>\n<ul>\n<li> <strong>\u5143\u7ec4<\/strong>\uff1a\u4e00\u4e2a\u4e0d\u53ef\u53d8\u7684\u5e8f\u5217\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4e00\u65e6\u521b\u5efa\u5c31\u65e0\u6cd5\u66f4\u6539\u3002\u5f53\u60a8\u60f3\u8981\u786e\u4fdd\u6570\u636e\u4fdd\u6301\u4e0d\u53d8\u65f6\uff0c\u5143\u7ec4\u975e\u5e38\u6709\u7528\u3002 <\/li>\n<\/ul>\n<pre>  my_tuple = (1, 2, \"apple\", 3.5)\n  # attempting to modify will raise an error\n<\/pre>\n<p><strong>\u5b57\u5178<\/strong>\u5c06\u6570\u636e\u5b58\u50a8\u5728\u952e\u503c\u5bf9\u4e2d\uff0c\u5141\u8bb8\u60a8\u901a\u8fc7\u5176\u952e\u68c0\u7d22\u4fe1\u606f\u3002\u8fd9\u5728\u5904\u7406\u76f8\u5173\u6570\u636e\u65f6\u7279\u522b\u6709\u7528\u3002<\/p>\n<pre>my_dict = {\n    \"name\": \"Sakshi\",\n    \"age\": 20,\n    \"canVote\": True\n}\n\nprint(my_dict[\"name\"])  # Outputs: Sakshi\n<\/pre>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cmy_dict \u4f7f\u7528\u952e\uff08\u59d3\u540d\u3001\u5e74\u9f84\u3001canvote\uff09\u6620\u5c04\u5230\u5404\u81ea\u7684\u503c\u3002<\/p>\n<hr>\n<p>\u5728 python \u4e2d\uff0c\u4e00\u5207\u90fd\u88ab\u89c6\u4e3a\u5bf9\u8c61\uff0c\u4ece\u6574\u6570\u5230\u590d\u6742\u7684\u6570\u636e\u7ed3\u6784\uff08\u5982\u5217\u8868\u548c\u5b57\u5178\uff09\u3002\u7406\u89e3\u8fd9\u4e00\u539f\u5219\u81f3\u5173\u91cd\u8981\uff0c\u56e0\u4e3a\u5b83\u4f7f python \u5177\u6709\u9ad8\u5ea6\u52a8\u6001\u6027\uff0c\u4e3a\u7528\u6237\u63d0\u4f9b\u4e86\u7075\u6d3b\u6027\u3002\u5373\u4f7f\u662f\u7b80\u5355\u7684\u6570\u636e\u7c7b\u578b\uff08\u4f8b\u5982 int \u548c str\uff09\u4e5f\u662f\u5404\u81ea\u7c7b\u7684\u5bf9\u8c61\u3002<\/p>\n<hr>\n<p>\u5728\u672c\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u63a2\u7d22\u4e86 python \u4e2d\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b\u7684\u57fa\u7840\u77e5\u8bc6\u3002\u8fd9\u4e9b\u6784\u5efa\u5757\u4e3a python \u7f16\u7a0b\u4e2d\u66f4\u9ad8\u7ea7\u7684\u6982\u5ff5\u94fa\u5e73\u4e86\u9053\u8def\uff0c\u56e0\u6b64\u5f7b\u5e95\u638c\u63e1\u5b83\u4eec\u81f3\u5173\u91cd\u8981\u3002 python \u5728\u5904\u7406\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u65b9\u9762\u7684\u7b80\u5355\u6027\u548c\u591a\u529f\u80fd\u6027\u4f7f\u5176\u6210\u4e3a\u521d\u5b66\u8005\u548c\u4e13\u5bb6\u7684\u7edd\u4f73\u9009\u62e9\u3002<\/p>\n<p>\u51c6\u5907\u597d\u7ec3\u4e60\u4e86\u5417\uff1f\u5c1d\u8bd5\u5b9a\u4e49\u4e00\u4e9b\u5177\u6709\u4e0d\u540c\u6570\u636e\u7c7b\u578b\u7684\u53d8\u91cf\u5e76\u6267\u884c\u64cd\u4f5c\u4ee5\u67e5\u770b python \u7684\u54cd\u5e94\u3002\u4e0d\u8981\u5fd8\u8bb0\u63a2\u7d22\u5217\u8868\u3001\u5143\u7ec4\u548c\u5b57\u5178\uff0c\u4ee5\u4e86\u89e3\u5982\u4f55\u6709\u6548\u5730\u7ec4\u7ec7\u6570\u636e\u3002\u5feb\u4e50\u7f16\u7801\uff01<\/p>\n<p>\u8bf7\u6211\u559d\u676f\u5496\u5561<\/p>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300a\u65e5\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b | \u5929\u87d2\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e5\u53d8\u91cf\u548c\u6570\u636e\u7c7b\u578b | \u5929\u87d2 \u76ee\u524d&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205263","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205263"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205263\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}