{"id":204659,"date":"2025-05-29T14:01:50","date_gmt":"2025-05-29T06:01:50","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204659\/"},"modified":"2025-05-29T14:01:50","modified_gmt":"2025-05-29T06:01:50","slug":"python%ef%bc%9a%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204659\/","title":{"rendered":"Python\uff1a\u53d8\u91cf"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python\uff1a\u53d8\u91cf<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPython\uff1a\u53d8\u91cf\u300b<\/span>\u4e3b\u8981\u8bb2\u89e3\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241112\/17314094286733361452a34.jpg\" class=\"aligncenter\"><\/p>\n<p>\u5927\u5bb6\u597d\uff0c<br \/> \u4eca\u5929\u6211\u4eec\u8981\u5b66\u4e60python\u53d8\u91cf\u3002<\/p>\n<ol>\n<li>\u5e38\u89c1\u53d8\u91cf\u4f1a\u4fdd\u7559\u4e00\u4e9b\u503c\uff0c\u5982 str\u3001int \u7b49<\/li>\n<li>python \u6ca1\u6709\u4f7f\u7528\u4efb\u4f55\u547d\u4ee4\u6765\u58f0\u200b\u200b\u660e\u53d8\u91cf\uff0c\u5f53\u503c 3. \u9996\u5148\u5206\u914d\u65f6\uff0c\u53d8\u91cf\u88ab\u521b\u5efa\u5e76\u4e14\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li>\n<li>\u53d8\u91cf\u4e0d\u9700\u8981\u58f0\u660e\u4e3a\u4efb\u4f55\u7279\u5b9a\u7c7b\u578b\uff0c\u751a\u81f3\u53ef\u4ee5\u5728\u8bbe\u7f6e\u540e\u66f4\u6539\u7c7b\u578b\u3002 <\/li>\n<\/ol>\n<pre>a=1         # variable as int\nb=\"aravin\"  # variable as string\nx=5         # first assign the int value to x\nx='aravin'  # later assign the str value to x\nprint(x)    # o\/p aravin, recently assign value to use same variable.\n<\/pre>\n<h6> \u533a\u5206\u5927\u5c0f\u5199 <\/h6>\n<pre>a=100\na='india' # a will not overwrite to a both are diff.\nprint(a)\nprint(a)\n<\/pre>\n<h6> \u83b7\u53d6\u53d8\u91cf\u7c7b\u578b <\/h6>\n<pre>var=100\nmvar='hello'\nprint(type(var))\n<\/pre>\n<h6> \u521b\u5efa\u53d8\u91cf\u7684\u89c4\u5219 <\/h6>\n<ol>\n<li>\u53d8\u91cf\u540d\u79f0\u5e94\u4ee5\u5b57\u7b26\u6216\u4e0b\u5212\u7ebf\u5b57\u7b26\u5f00\u5934\u3002<\/li>\n<li>\u4e0d\u5e94\u4ee5\u6570\u5b57\u5f00\u5934\u3002<\/li>\n<li>\u4e0d\u80fd\u662f\u4efb\u4f55python\u5173\u952e\u5b57\u3002<\/li>\n<\/ol>\n<p><strong><em>\u4f8b\u5982\uff1a<\/em><\/strong><br \/> \u6b63\u786e\u540d\u79f0\uff1a<br \/> my_variable_name = &#8220;aravin&#8221; #\u86c7\u7c7b\u578b<br \/> myvariablename = &#8220;aravin&#8221; #\u9a86\u9a7c\u7c7b\u578b<br \/> myvariablename = &#8220;aravin&#8221; #pascal \u7c7b\u578b<br \/> myvarname =\u201c\u963f\u62c9\u6587\u201d<br \/> _myvarname =\u201c\u963f\u62c9\u6587\u201d<br \/> myvar_name = &#8220;\u963f\u62c9\u6587&#8221;<br \/> myvar21 =\u201c\u963f\u62c9\u6587\u201d<\/p>\n<p>\u4e0d\u6b63\u786e\u7684\u540d\u79f0\uff1a<br \/> 2myvar =\u201c\u4f60\u597d\u201d<br \/> my-var =\u201c\u4f60\u597d\u201d<br \/> \u6211\u7684 var =\u201c\u4f60\u597d\u201d<\/p>\n<h6> \u5c06\u591a\u4e2a\u503c\u5206\u914d\u7ed9\u591a\u4e2a\u53d8\u91cf <\/h6>\n<pre>a,b,c = 5,\"aravin\",\"db\"\n<\/pre>\n<h6> \u4e00\u4e2a\u503c\u5230\u591a\u4e2a\u53d8\u91cf <\/h6>\n<pre>a = b = c = \"apple\"\n<\/pre>\n<h6> \u89e3\u538b\u96c6\u5408 <\/h6>\n<pre>myvar = [\"var1\",\"var2\",\"var3\"]\na,b,c = myvar\nprint(myvar)\nprint(b)\n<\/pre>\n<h5> \u5168\u5c40\u53d8\u91cf <\/h5>\n<ol>\n<li>\u5728\u79f0\u4e3a\u5168\u5c40\u53d8\u91cf\u7684\u51fd\u6570\u5916\u90e8\u521b\u5efa\u6216\u4f7f\u7528 global \u5173\u952e\u5b57\u521b\u5efa\u3002<\/li>\n<li>\u5168\u5c40\u53d8\u91cf\u53ef\u4ee5\u88ab\u51fd\u6570\u5185\u90e8\u548c\u5916\u90e8\u7684\u6bcf\u4e2a\u4eba\u4f7f\u7528<\/li>\n<\/ol>\n<p><strong><em>\u4f8b\u5982\uff1a<\/em><\/strong><\/p>\n<h6> \u5728\u51fd\u6570\u5916\u90e8\u521b\u5efa <\/h6>\n<pre>a = \"python\"\ndef myfunc():\n  print(\"hello \" + a)\nmyfunc()\n<\/pre>\n<h6> \u51fd\u6570\u5185\u90e8\u521b\u5efa\u7684\u53d8\u91cf\uff0c\u4e0e\u5168\u5c40\u540c\u540d <\/h6>\n<pre>a = \"python\"\ndef myfunc():\n  a = \"python\"\n  print(\"hai \" + a)\nmyfunc()\nprint(\"hello \" + a)\n<\/pre>\n<h6> \u5728\u51fd\u6570\u5185\u4f7f\u7528 global \u5173\u952e\u5b57\u521b\u5efa\u5168\u5c40\u53d8\u91cf <\/h6>\n<pre>def myfunc():\n  global a\n  a = \"python\"\nmyfunc()\nprint(\"hello \" + a)\n<\/pre>\n<h6> \u66f4\u6539\u51fd\u6570\u5185\u7684\u5168\u5c40\u53d8\u91cf\u503c <\/h6>\n<pre>a = \"python\"\ndef myfunc():\n  global a\n  a = \"Python\"\nmyfunc()\nprint(\"Hai \" + x)\n<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPython\uff1a\u53d8\u91cf\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\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>Python\uff1a\u53d8\u91cf \u4ece\u73b0\u5728\u5f00\u59cb\uff0c&#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-204659","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204659","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=204659"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204659\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204659"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204659"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}