{"id":205100,"date":"2025-05-29T15:09:23","date_gmt":"2025-05-29T07:09:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205100\/"},"modified":"2025-05-29T15:09:23","modified_gmt":"2025-05-29T07:09:23","slug":"js-%e5%bc%80%e5%8f%91%e4%ba%ba%e5%91%98%e7%9a%84-python-%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205100\/","title":{"rendered":"JS \u5f00\u53d1\u4eba\u5458\u7684 Python \u57fa\u7840\u77e5\u8bc6"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>JS \u5f00\u53d1\u4eba\u5458\u7684 Python \u57fa\u7840\u77e5\u8bc6<\/h1>\n<p><span style=\"font-size: 15px\">\u5b66\u4e60\u77e5\u8bc6\u8981\u5584\u4e8e\u601d\u8003\uff0c\u601d\u8003\uff0c\u518d\u601d\u8003\uff01\u4eca\u5929\u5c0f\u7f16\u5c31\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aJS \u5f00\u53d1\u4eba\u5458\u7684 Python \u57fa\u7840\u77e5\u8bc6\u300b<\/span>\uff0c\u4ee5\u4e0b\u5185\u5bb9\u4e3b\u8981\u5305\u542b<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60\u6216\u51c6\u5907\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u5c31\u90fd\u4e0d\u8981\u9519\u8fc7\u672c\u6587\u5566~\u8ba9\u6211\u4eec\u4e00\u8d77\u6765\u770b\u770b\u5427\uff0c\u80fd\u5e2e\u52a9\u5230\u4f60\u5c31\u66f4\u597d\u4e86\uff01<\/span><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323540726741a018d2871.jpg\" class=\"aligncenter\"><\/p>\n<h4> <strong>1.\u57fa\u672c\u8bed\u6cd5\u548c\u6570\u636e\u7c7b\u578b<\/strong> <\/h4>\n<ul>\n<li>\n<p><strong>\u53d8\u91cf\u58f0\u660e<\/strong>\uff1a\u4e0d\u9700\u8981 var\u3001let \u6216 const\u3002\u53ea\u9700\u547d\u540d\u53d8\u91cf\u5373\u53ef\u3002<\/p>\n<pre> x = 10\n name = \"python\"\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u539f\u59cb\u7c7b\u578b<\/strong>:<\/p>\n<ul>\n<li> int\uff08\u6574\u6570\uff09<\/li>\n<li> \u6d6e\u52a8\uff08\u6d6e\u70b9\uff09<\/li>\n<li> str\uff08\u5b57\u7b26\u4e32\uff09<\/li>\n<li> \u5e03\u5c14\uff08\u5e03\u5c14\u503c\uff09<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6570\u636e\u7ed3\u6784<\/strong>:<\/p>\n<ul>\n<li> <strong>\u5217\u8868<\/strong>\uff08\u5c31\u50cf js \u4e2d\u7684\u6570\u7ec4\uff09\uff1a <\/li>\n<\/ul>\n<pre>   numbers = [1, 2, 3]\n   numbers.append(4)\n<\/pre>\n<ul>\n<li> <strong>\u5143\u7ec4<\/strong>\uff08\u4e0d\u53ef\u53d8\u5217\u8868\uff09\uff1a <\/li>\n<\/ul>\n<pre>   point = (10, 20)\n<\/pre>\n<ul>\n<li> <strong>\u5b57\u5178<\/strong>\uff08\u5982 js \u5bf9\u8c61\uff09\uff1a <\/li>\n<\/ul>\n<pre>   person = {\"name\": \"alice\", \"age\": 30}\n   person[\"name\"]  # accessing value\n<\/pre>\n<ul>\n<li> <strong>\u96c6\u5408<\/strong>\uff08\u552f\u4e00\u7684\u3001\u65e0\u5e8f\u7684\u5143\u7d20\uff09\uff1a <\/li>\n<\/ul>\n<pre>   unique_numbers = {1, 2, 3, 2}\n<\/pre>\n<\/li>\n<\/ul>\n<h4> <strong>2.\u63a7\u5236\u7ed3\u6784<\/strong> <\/h4>\n<ul>\n<li>\n<p><strong>\u6761\u4ef6<\/strong>:<\/p>\n<pre> if x &gt; 5:\n     print(\"greater\")\n elif x == 5:\n     print(\"equal\")\n else:\n     print(\"lesser\")\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u5faa\u73af<\/strong>:<\/p>\n<ul>\n<li> <strong>for loop<\/strong>\uff08\u9002\u7528\u4e8e\u53ef\u8fed\u4ee3\u5bf9\u8c61\uff09\uff1a <\/li>\n<\/ul>\n<pre>   for num in [1, 2, 3]:\n       print(num)\n<\/pre>\n<ul>\n<li> <strong>while \u5faa\u73af<\/strong>\uff1a <\/li>\n<\/ul>\n<pre>   i = 0\n   while i &lt; 5:\n       i += 1\n<\/pre>\n<\/li>\n<\/ul>\n<h4> <strong>3.\u529f\u80fd<\/strong> <\/h4>\n<ul>\n<li>\n<p>\u51fd\u6570\u5b9a\u4e49\u548c\u8fd4\u56de\u8bed\u6cd5\uff1a<\/p>\n<pre> def greet(name):\n     return f\"hello, {name}\"\n<\/pre>\n<\/li>\n<li>\n<p><strong>lambda \u51fd\u6570<\/strong>\uff08\u5982 js \u7bad\u5934\u51fd\u6570\uff09\uff1a<\/p>\n<pre> square = lambda x: x * x\n<\/pre>\n<\/li>\n<\/ul>\n<h4> <strong>4.\u5217\u8868\u63a8\u5bfc\u5f0f\u548c\u751f\u6210\u5668<\/strong> <\/h4>\n<ul>\n<li>\n<p><strong>\u5217\u8868\u63a8\u5bfc\u5f0f<\/strong>\uff08\u521b\u5efa\u5217\u8868\u7684\u6709\u6548\u65b9\u6cd5\uff09\uff1a<\/p>\n<pre> squares = [x * x for x in range(10)]\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u751f\u6210\u5668<\/strong>\uff08\u4e00\u4e00\u4ea7\u751f\u503c\uff09\uff1a<\/p>\n<pre> def generate_numbers(n):\n     for i in range(n):\n         yield i\n<\/pre>\n<\/li>\n<\/ul>\n<h4> <strong>5.\u9519\u8bef\u5904\u7406<\/strong> <\/h4>\n<ul>\n<li>\n<p><strong>\u5c1d\u8bd5\/\u6392\u9664\u5757<\/strong>:<\/p>\n<pre> try:\n     result = 10 \/ 0\n except zerodivisionerror:\n     print(\"cannot divide by zero\")\n<\/pre>\n<\/li>\n<\/ul>\n<h4> <strong>6.\u7c7b\u548c oop<\/strong> <\/h4>\n<ul>\n<li>\n<p><strong>\u7c7b\u5b9a\u4e49<\/strong>:<\/p>\n<pre> class animal:\n     def __init__(self, name):\n         self.name = name\n\n     def speak(self):\n         return f\"{self.name} makes a sound\"\n<\/pre>\n<\/li>\n<li>\n<p><strong>\u7ee7\u627f<\/strong>:<\/p>\n<pre> class dog(animal):\n     def speak(self):\n         return f\"{self.name} barks\"\n<\/pre>\n<\/li>\n<\/ul>\n<h4> <strong>7.\u5e38\u7528\u5185\u7f6e\u51fd\u6570<\/strong> <\/h4>\n<ul>\n<li> len()\u3001max()\u3001min()\u3001sum()\u3001\u6392\u5e8f() <\/li>\n<li>\u7c7b\u578b\u8f6c\u6362\uff1aint()\u3001float()\u3001str()\u3001list()\u3001dict() <\/li>\n<\/ul>\n<h4> <strong>8.\u4f7f\u7528\u6587\u4ef6<\/strong> <\/h4>\n<ul>\n<li>\n<p><strong>\u9605\u8bfb\u548c\u5199\u4f5c<\/strong>:<\/p>\n<pre> with open(\"file.txt\", \"r\") as file:\n     data = file.read()\n<\/pre>\n<\/li>\n<\/ul>\n<h4> <strong>9.\u91cd\u8981\u56fe\u4e66\u9986<\/strong> <\/h4>\n<ul>\n<li> <strong>numpy<\/strong> \u7528\u4e8e\u6570\u503c\u8fd0\u7b97\uff0c<strong>pandas<\/strong> \u7528\u4e8e\u6570\u636e\u64cd\u4f5c\uff0c<strong>matplotlib<\/strong> \u7528\u4e8e\u7ed8\u56fe\u3002<\/li>\n<\/ul>\n<h4> <strong>10\u3002\u4e0e javascript \u7684\u533a\u522b<\/strong> <\/h4>\n<ul>\n<li>\u4e0d\u9700\u8981\u5206\u53f7\u3002<\/li>\n<li>\u5b9a\u4e49\u5757\u65f6\u5fc5\u987b\u7f29\u8fdb\u3002<\/li>\n<li>\u6ca1\u6709 switch \u8bed\u53e5\uff08\u4f7f\u7528 if-elif \u4ee3\u66ff\uff09\u3002<\/li>\n<li> \u4f7f\u7528 none \u4ee3\u66ff null\u3002<\/li>\n<\/ul>\n<hr>\n<p>\u6b64\u6458\u8981\u5e94\u63d0\u4f9b\u6709\u6548\u5f00\u59cb\u4f7f\u7528 python \u8fdb\u884c\u7f16\u7801\u7684\u57fa\u7840\u77e5\u8bc6\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300aJS \u5f00\u53d1\u4eba\u5458\u7684 Python \u57fa\u7840\u77e5\u8bc6\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6587\u7ae0\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\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>JS \u5f00\u53d1\u4eba\u5458\u7684 Python &#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-205100","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205100","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=205100"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205100\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}