{"id":272,"date":"2024-04-28T02:29:59","date_gmt":"2024-04-27T18:29:59","guid":{"rendered":"https:\/\/669082.xyz\/?p=272"},"modified":"2024-04-29T00:00:49","modified_gmt":"2024-04-28T16:00:49","slug":"2240428%e5%ad%a6%e4%b9%a0python_%e7%b3%bb%e7%bb%9f%e5%8c%96%e5%ad%a6%e4%b9%a0","status":"publish","type":"post","link":"https:\/\/669082.xyz\/index.php\/2024\/04\/28\/2240428%e5%ad%a6%e4%b9%a0python_%e7%b3%bb%e7%bb%9f%e5%8c%96%e5%ad%a6%e4%b9%a0\/","title":{"rendered":"20240428\u5b66\u4e60Python_\u57fa\u7840"},"content":{"rendered":"<h5>helloWorld<\/h5>\n<pre><code class=\"language-python\">print(&#039;Hello World&#039;)<\/code><\/pre>\n<h5>Python\u57fa\u7840\u8bed\u6cd5<\/h5>\n<h6>\u6ce8\u91ca<\/h6>\n<h6>\u5355\u884c\u6ce8\u91ca\u7528 # \u53f7<\/h6>\n<h6>\u591a\u884c\u6ce8\u91ca\u7528 &#8221;&#8217; &#8221;&#8217; \u6216\u8005 &quot;&quot;&quot; &quot;&quot;&quot;<\/h6>\n<pre><code class=\"language-python\"># \u8fd9\u662f\u4e00\u4e2a\u6ce8\u91ca \u5355\u884c\u6ce8\u91ca\n\n&#039;&#039;&#039;\n\u8fd9\u662f\u591a\u884c\u6ce8\u91ca\uff0c\u7528\u4e09\u4e2a\u5355\u5f15\u53f7\n\u8fd9\u662f\u591a\u884c\u6ce8\u91ca\uff0c\u7528\u4e09\u4e2a\u5355\u5f15\u53f7 \n\u8fd9\u662f\u591a\u884c\u6ce8\u91ca\uff0c\u7528\u4e09\u4e2a\u5355\u5f15\u53f7\n&#039;&#039;&#039;\n\n&quot;&quot;&quot;\n\u8fd9\u662f\u591a\u884c\u6ce8\u91ca\uff08\u5b57\u7b26\u4e32\uff09\uff0c\u7528\u4e09\u4e2a\u53cc\u5f15\u53f7\n\u8fd9\u662f\u591a\u884c\u6ce8\u91ca\uff08\u5b57\u7b26\u4e32\uff09\uff0c\u7528\u4e09\u4e2a\u53cc\u5f15\u53f7 \n\u8fd9\u662f\u591a\u884c\u6ce8\u91ca\uff08\u5b57\u7b26\u4e32\uff09\uff0c\u7528\u4e09\u4e2a\u53cc\u5f15\u53f7\n&quot;&quot;&quot;<\/code><\/pre>\n<h6>\u7f29\u8fdb<\/h6>\n<h6>python\u91cc\u7f29\u8fdb\u8868\u793a\u4e00\u4e2a\u4ee3\u7801\u5757,\u5e76\u4e14\u662f\u5f3a\u5236\u8fd9\u4e48\u505a.\u800c\u4e0d\u662f\u50cf\u5176\u5b83\u8bed\u8a00\u91cc\u7528\u5927\u62ec\u53f7<\/h6>\n<pre><code class=\"language-python\">if 5 &gt; 2:\n  print(&quot;Five is greater than two!&quot;)\n\nif True:\n    print (&quot;True&quot;)\nelse:\n    print (&quot;False&quot;)<\/code><\/pre>\n<h6>\u5f15\u53f7<\/h6>\n<h6>\u4f7f\u7528\u5f15\u53f7( &#8216; )\u3001\u53cc\u5f15\u53f7( &quot; )\u3001\u4e09\u5f15\u53f7( &#8221;&#8217; \u6216 &quot;&quot;&quot; ) \u6765\u8868\u793a\u5b57\u7b26\u4e32 \u5176\u4e2d\u53ea\u6709\u4e09\u5f15\u53f7\u53ef\u4ee5\u8868\u793a\u591a\u884c<\/h6>\n<pre><code class=\"language-python\">word = &#039;word&#039;\nsentence = &quot;\u8fd9\u662f\u4e00\u4e2a\u53e5\u5b50\u3002&quot;\nparagraph = &quot;&quot;&quot;\u8fd9\u662f\u4e00\u4e2a\u6bb5\u843d\u3002\n\u8fd9\u662f\u4e00\u4e2a\u6bb5\u843d,\n\u5305\u542b\u4e86\u591a\u4e2a\u8bed\u53e5&quot;&quot;&quot;<\/code><\/pre>\n<h6>\u540c\u4e00\u884c\u53ef\u4ee5\u5199\u591a\u6761\u8bed\u53e5 \u8981\u7528;\u9694\u5f00<\/h6>\n<pre><code class=\"language-python\">import sys; x = &#039;runoob&#039;; sys.stdout.write(x + &#039;\\n&#039;)<\/code><\/pre>\n<h5>python\u53d8\u91cf<\/h5>\n<h6>python\u662f\u5f31\u7c7b\u578b\u8bed\u8a00 \u58f0\u660e\u7684\u65f6\u5019\u4e0d\u9700\u8981\u7c7b\u578b<\/h6>\n<pre><code class=\"language-python\">x = 10\ny = &quot;Bill&quot;\nprint(x)\nprint(y)<\/code><\/pre>\n<pre><code class=\"language-python\">#\u8bed\u6cd5 \u6bd4\u8f83\u7075\u6d3b \u4e00\u884c\u58f0\u660e\u591a\u4e2a\u53d8\u91cf\nx, y, z = &quot;Orange&quot;, &quot;Banana&quot;, &quot;Cherry&quot;\nprint(x)\nprint(y)\nprint(z)\n\n#\u4e5f\u53ef\u4ee5\u5728\u4e00\u884c\u4e2d\u4e3a\u591a\u4e2a\u53d8\u91cf \u8d4b\u76f8\u540c\u7684\u503c\nx = y = z = &quot;Orange&quot;\nprint(x)\nprint(y)\nprint(z)\n<\/code><\/pre>\n<h6>\u53d8\u91cf\u8f93\u51fa<\/h6>\n<pre><code class=\"language-python\"># + \u53f7\u53ef\u4ee5\u7528\u6765\u8fde\u63a5\u5b57\u7b26\u4e32\nx = &quot;awesome&quot;\nprint(&quot;Python is &quot; + x)\n\nx = &quot;Python is &quot;\ny = &quot;awesome&quot;\nz =  x + y\nprint(z)\n\n#\u5bf9\u4e8e\u6570\u5b57 + \u53f7\u4f5c\u4e3a\u6570\u5b66\u8fd0\u7b97\u7b26\nx = 5\ny = 10\nprint(x + y)\n\n#\u6ce8\u610f \u4e0d\u5141\u8bb8\u4ee5\u4e0b\u8fd9\u6837 \u4f1a\u62a5\u9519 \u8ba9\u6570\u5b57\u4e0e\u5b57\u7b26 \u505a + \u8fd0\u884c\nx = 10\ny = &quot;Bill&quot;\nprint(x + y)\n\n#\u51fd\u6570\u5916\u90e8\u521b\u5efa\u53d8\u91cf \u5e76\u5728\u51fd\u6570\u5185\u90e8\u4f7f\u7528\u5b83\n#\u51fd\u6570\u5916\u90e8\u521b\u5efa\u7684\u53d8\u91cf \u770b\u8d77\u6765\u50cf\u5168\u5c40\u53d8\u91cf\nx = &quot;awesome&quot;\ndef myfunc():\n  print(&quot;Python is &quot; + x)\nmyfunc()\n\n#\u6ce8\u610f:\u5982\u679c\u51fd\u6570\u5185\u90e8\u6709\u91cd\u540d\u53d8\u91cf \u5916\u90e8\u53d8\u91cf\u5c06\u88ab\u8986\u76d6\nx = &quot;awesome&quot;\ndef myfunc():\n  x = &quot;fantastic&quot;\n  print(&quot;Python is &quot; + x)\nmyfunc()\nprint(&quot;Python is &quot; + x)\n\n#\u51fd\u6570\u5185\u90e8\u521b\u5efa\u7684\u53d8\u91cf \u4ec5\u4ec5\u53ea\u662f\u5c40\u90e8\u53d8\u91cf \u5982\u679c\u60f3\u5168\u5c40\u4f7f\u7528 \u9700\u8981global\ndef myfunc():\n  global x\n  x = &quot;fantastic&quot;\nmyfunc()\nprint(&quot;Python is &quot; + x)\n\n#\u5728\u51fd\u6570\u5185\u90e8\u66f4\u6539\u5168\u5c40\u53d8\u91cf\u7684\u503c \u9700\u8981global\nx = &quot;awesome&quot;\ndef myfunc():\n  global x\n  x = &quot;fantastic&quot;\nmyfunc()\nprint(&quot;Python is &quot; + x)<\/code><\/pre>\n<h5>python\u4e2d\u7684\u6570\u636e\u7c7b\u578b<\/h5>\n<h6>\u9ed8\u8ba4\u62e5\u6709\u4ee5\u4e0b\u6570\u636e\u7c7b\u578b<\/h6>\n<p><img decoding=\"async\" src=\"https:\/\/669082.xyz\/wp-content\/uploads\/2024\/04\/image-1714244565652.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-python\">#\u6253\u5370\u4e00\u4e2a\u53d8\u91cf\u7684\u6570\u636e\u7c7b\u578b\nx = 10\nprint(type(x))\n\n#\u5728 Python \u4e2d\uff0c\u5f53\u60a8\u4e3a\u53d8\u91cf\u8d4b\u503c\u65f6\uff0c\u4f1a\u8bbe\u7f6e\u6570\u636e\u7c7b\u578b\uff1a\nx = &quot;Hello World&quot;  #str\nx = 29  #int\nx = 29.5  #float\nx = 1j  #complex\nx = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]  #list\nx = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)  #tuple\nx = range(6)  #range\nx = {&quot;name&quot; : &quot;Bill&quot;, &quot;age&quot; : 63}  #dict\nx = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}  #set\nx = frozenset({&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;})  #frozenset\nx = True  #bool\nx = b&quot;Hello&quot;  #bytes\nx = bytearray(5)  #bytearray\nx = memoryview(bytes(5))  #memoryview<\/code><\/pre>\n<h5>\u6570\u636e\u7c7b\u578b \u6570\u5b57<\/h5>\n<pre><code class=\"language-python\">#Python \u4e2d\u6709\u4e09\u79cd\u6570\u5b57\u7c7b\u578b\uff1aint float complex\nx = 10   # int\ny = 6.3  # float\nz = 2j   # complex\nprint(type(x))\nprint(type(y))\nprint(type(z))\n\n#\u7c7b\u578b\u8f6c\u6362\n#\u53ef\u4ee5\u4f7f\u7528 int()\u3001float() \u548c complex() \u65b9\u6cd5\u4ece\u4e00\u79cd\u7c7b\u578b\u8f6c\u6362\u4e3a\u53e6\u4e00\u79cd\u7c7b\u578b\uff1a\nx = 10 # int\ny = 6.3 # float\nz = 1j # complex\n# \u628a\u6574\u6570\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\na = float(x)\n# \u628a\u6d6e\u70b9\u6570\u8f6c\u6362\u4e3a\u6574\u6570\nb = int(y)\n# \u628a\u6574\u6570\u8f6c\u6362\u4e3a\u590d\u6570\uff1a\nc = complex(x)\nprint(a)\nprint(b)\nprint(c)\nprint(type(a))\nprint(type(b))\nprint(type(c))\n\n#\u968f\u673a\u6570 \u9700\u8981\u7528\u5230 random \u6a21\u5757\n#1 \u5230 9 \u4e4b\u95f4\u7684\u968f\u673a\u6570\uff1a\nimport random\nprint(random.randrange(1,10))\n\n#\u6570\u5b57\u4e0e\u5b57\u7b26\u4e32\u4e4b\u95f4\u7684\u8f6c\u6362\nx = int(1)   # x \u5c06\u662f 1\ny = int(2.5) # y \u5c06\u662f 2\nz = int(&quot;3&quot;) # z \u5c06\u662f 3\n\nx = float(1)     # x \u5c06\u662f 1.0\ny = float(2.5)   # y \u5c06\u662f 2.5\nz = float(&quot;3&quot;)   # z \u5c06\u662f 3.0\nw = float(&quot;4.6&quot;) # w \u5c06\u662f 4.6\n\nx = str(&quot;S2&quot;) # x \u5c06\u662f &#039;S2&#039;\ny = str(3)    # y \u5c06\u662f &#039;3&#039;\nz = str(4.0)  # z \u5c06\u662f &#039;4.0&#039;<\/code><\/pre>\n<h5>\u5b57\u7b26\u4e32<\/h5>\n<pre><code class=\"language-python\">#\u5b57\u7b26\u4e32\u5b9a\u4e49\n#\u53ef\u4ee5\u7531 \u5355\u5f15\u53f7 &#039; &#039; ,\u53cc\u5f15\u53f7 &quot; &quot; , \u4e09\u4e2a\u5355\u5f15\u53f7 &#039;&#039;&#039; &#039;&#039;&#039;, \u4e09\u4e2a\u53cc\u5f15\u53f7 &quot;&quot;&quot; &quot;&quot;&quot; \u6765\u5b9a\u4e49\na = &quot;Hello&quot;\n\na = &#039;Hello&#039;\n\na = &#039;&#039;&#039;Python is a widely used general-purpose, high level programming language.\nand its syntax allows programmers to express concepts in fewer lines of code.&#039;&#039;&#039;\n\na = &quot;&quot;&quot;Python is a widely used general-purpose, high level programming language.\nand its syntax allows programmers to express concepts in fewer lines of code.&quot;&quot;&quot;\n\n#\u5b57\u7b26\u4e32\u53ef\u4ee5\u50cf\u6570\u7ec4\u90a3\u6837\u901a\u8fc7\u4e0b\u6807\u53d6\u503c\na = &quot;Hello, World!&quot;\nprint(a[1])\n\n#\u4e5f\u53ef\u4ee5\u50cf\u6570\u7ec4\u90a3\u6837\u53d6\u591a\u4e2a\u503c\nb = &quot;Hello, World!&quot;\nprint(b[2:5])\n#\u4ece\u672b\u5c3e\u5f00\u59cb\u6570\nb = &quot;Hello, World!&quot;\nprint(b[-5:-2])\n\n#\u5b57\u7b26\u4e32\u957f\u5ea6 len()\na = &quot;Hello, World!&quot;\nprint(len(a))\n\n#\u5b57\u7b26\u4e32 strip() \u6e05\u9664\u6389\u5de6\u53f3\u7a7a\u767d PHP\u91cc\u7684trim\na = &quot; Hello, World! &quot;\nprint(a.strip()) # returns &quot;Hello, World!&quot;\n\n#lower() \u8fd4\u56de\u5c0f\u5199\u7684\u5b57\u7b26\u4e32\uff1a\na = &quot;Hello, World!&quot;\nprint(a.lower())\n\n#upper() \u65b9\u6cd5\u8fd4\u56de\u5927\u5199\u7684\u5b57\u7b26\u4e32\uff1a\na = &quot;Hello, World!&quot;\nprint(a.upper())\n\n#replace() \u7528\u53e6\u4e00\u6bb5\u5b57\u7b26\u4e32\u6765\u66ff\u6362\u5b57\u7b26\u4e32\uff1a\na = &quot;Hello, World!&quot;\nprint(a.replace(&quot;World&quot;, &quot;Kitty&quot;))\n\n#split() \u7528\u5206\u5272\u7b26\u5207\u5272\u5b57\u7b26\u4e32\uff0c\u8fd4\u56deList\na = &quot;Hello, World!&quot;\nprint(a.split(&quot;,&quot;)) # returns [&#039;Hello&#039;, &#039; World!&#039;]\n\n#\u68c0\u67e5\u4ee5\u4e0b\u6587\u672c\u4e2d\u662f\u5426\u5b58\u5728\u77ed\u8bed &quot;jap&quot;\uff1a\ntxt = &quot;japan is a great country&quot;\nx = &quot;jap&quot; in txt\nprint(x)\n\n#\u68c0\u67e5\u4ee5\u4e0b\u6587\u672c\u4e2d\u662f\u5426\u6ca1\u6709\u77ed\u8bed &quot;jap&quot;\uff1a\ntxt = &quot;japan is a great country&quot;\nx = &quot;jap&quot; not in txt\nprint(x)\n\n#\u5b57\u7b26\u4e32\u8fde\u63a5\na = &quot;Hello&quot;\nb = &quot;World&quot;\nc = a + b\nprint(c)\n\na = &quot;Hello&quot;\nb = &quot;World&quot;\nc = a + &quot; &quot; + b\nprint(c)\n\n#format() \u65b9\u6cd5\u7ec4\u5408\u5b57\u7b26\u4e32\u548c\u6570\u5b57\nage = 63\ntxt = &quot;My name is Bill, and I am {}&quot;\nprint(txt.format(age))\n\nquantity = 3\nitemno = 567\nprice = 49.95\nmyorder = &quot;I want {} pieces of item {} for {} dollars.&quot;\nprint(myorder.format(quantity, itemno, price))\n\n#\u4f7f\u7528\u7d22\u5f15\u53f7 {0} \u6765\u786e\u4fdd\u53c2\u6570\u88ab\u653e\u5728\u6b63\u786e\u7684\u5360\u4f4d\u7b26\u4e2d\nquantity = 3\nitemno = 567\nprice = 49.95\nmyorder = &quot;I want to pay {2} dollars for {0} pieces of item {1}.&quot;\nprint(myorder.format(quantity, itemno, price))\n<\/code><\/pre>\n<h5>Python \u5e03\u5c14<\/h5>\n<h6>\u5e03\u5c14\u8868\u793a\u4e24\u503c\u4e4b\u4e00\uff1aTrue \u6216 False\u3002<\/h6>\n<pre><code class=\"language-python\">print(8 &gt; 7)\nprint(8 == 7)\nprint(8 &lt; 7)\n\na = 200\nb = 33\nif b &gt; a:\n  print(&quot;b is greater than a&quot;)\nelse:\n  print(&quot;b is not greater than a&quot;)\n\n#\u6570\u5b57\u548c\u5b57\u7b26\u4e32\u53ef\u4ee5\u8f6c\u6362\u6210\u5e03\u5c14\nprint(bool(&quot;Hello&quot;))\nprint(bool(10))\nbool([&quot;apple&quot;, &quot;cherry&quot;, &quot;banana&quot;])\n\nx = &quot;Hello&quot;\ny = 10\nprint(bool(x))\nprint(bool(y))\n\n#\u6ce8\u610f \u4e0b\u4f8b\u4f1a\u8fd4\u56de False\uff1a\n#False None 0 \u7a7a\u5b57\u7b26 \u7a7a\u5143\u7ec4 \u7a7a\u5217\u8868 \u7a7a\u5b57\u5178\nbool(False)\nbool(None)\nbool(0)\nbool(&quot;&quot;)\nbool(())\nbool([])\nbool({})\n\n#\u8fd9\u79cd\u60c5\u51b5\u4e5f\u4e3aFalse\nclass myclass():\n  def __len__(self):\n    return 0\nmyobj = myclass()\nprint(bool(myobj))\n\n#\u51fd\u6570\u8fd4\u56de\u5e03\u5c14\u503c\nx = 200\nprint(isinstance(x, int))\n<\/code><\/pre>\n<h5>\u8fd0\u7b97\u7b26<\/h5>\n<h6>Python \u7b97\u672f\u8fd0\u7b97\u7b26<\/h6>\n<p><img decoding=\"async\" src=\"https:\/\/669082.xyz\/wp-content\/uploads\/2024\/04\/image-1714248845667.png\" alt=\"file\" \/><\/p>\n<h6>Python \u8d4b\u503c\u8fd0\u7b97\u7b26<\/h6>\n<p><img decoding=\"async\" src=\"https:\/\/669082.xyz\/wp-content\/uploads\/2024\/04\/image-1714248911484.png\" alt=\"file\" \/><\/p>\n<h6>Python \u6bd4\u8f83\u8fd0\u7b97\u7b26<\/h6>\n<p><img decoding=\"async\" src=\"https:\/\/669082.xyz\/wp-content\/uploads\/2024\/04\/image-1714248949381.png\" alt=\"file\" \/><\/p>\n<h6>Python \u903b\u8f91\u8fd0\u7b97\u7b26<\/h6>\n<p><img decoding=\"async\" src=\"https:\/\/669082.xyz\/wp-content\/uploads\/2024\/04\/image-1714248984563.png\" alt=\"file\" \/><\/p>\n<h6>Python \u8eab\u4efd\u8fd0\u7b97\u7b26<\/h6>\n<p><img decoding=\"async\" src=\"https:\/\/669082.xyz\/wp-content\/uploads\/2024\/04\/image-1714249025030.png\" alt=\"file\" \/><\/p>\n<h6>Python \u6210\u5458\u8fd0\u7b97\u7b26<\/h6>\n<p><img decoding=\"async\" src=\"https:\/\/669082.xyz\/wp-content\/uploads\/2024\/04\/image-1714249050584.png\" alt=\"file\" \/><\/p>\n<h5>python \u56db\u79cd\u96c6\u5408\u6570\u636e\u7c7b\u578b\uff1a<\/h5>\n<h6>\u5217\u8868\uff08List\uff09\u662f\u4e00\u79cd\u6709\u5e8f\u548c\u53ef\u66f4\u6539\u7684\u96c6\u5408\u3002\u5141\u8bb8\u91cd\u590d\u7684\u6210\u5458\u3002<\/h6>\n<h6>\u5143\u7ec4\uff08Tuple\uff09\u662f\u4e00\u79cd\u6709\u5e8f\u4e14\u4e0d\u53ef\u66f4\u6539\u7684\u96c6\u5408\u3002\u5141\u8bb8\u91cd\u590d\u7684\u6210\u5458\u3002<\/h6>\n<h6>\u96c6\u5408\uff08Set\uff09\u662f\u4e00\u4e2a\u65e0\u5e8f\u548c\u65e0\u7d22\u5f15\u7684\u96c6\u5408\u3002\u6ca1\u6709\u91cd\u590d\u7684\u6210\u5458\u3002<\/h6>\n<h6>\u8bcd\u5178\uff08Dictionary\uff09\u662f\u4e00\u4e2a\u65e0\u5e8f\uff0c\u53ef\u53d8\u548c\u6709\u7d22\u5f15\u7684\u96c6\u5408\u3002\u6ca1\u6709\u91cd\u590d\u7684\u6210\u5458\u3002<\/h6>\n<h5>\u5217\u8868 list<\/h5>\n<pre><code class=\"language-python\">#\u521b\u5efa\u5217\u8868\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nprint(thislist)\n\n#\u6253\u5370\u5217\u8868\u7684\u7b2c\u4e8c\u9879\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nprint(thislist[1])\n\n#\u8d1f\u7684\u7d22\u5f15 \u4ece\u5c3e\u90e8\u5f00\u59cb\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nprint(thislist[-1])\n\n#\u7d22\u5f15\u8303\u56f4 \n#\u901a\u8fc7\u6307\u5b9a\u8303\u56f4\u7684\u8d77\u70b9\u548c\u7ec8\u70b9\u6765\u6307\u5b9a\u7d22\u5f15\u8303\u56f4\u3002\n#\u8fd4\u56de\u7b2c\u4e09\u3001\u7b2c\u56db\u3001\u7b2c\u4e94\u9879\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;orange&quot;, &quot;kiwi&quot;, &quot;melon&quot;, &quot;mango&quot;]\nprint(thislist[2:5])\n\n#\u6b64\u4f8b\u5c06\u8fd4\u56de\u4ece\u7d22\u5f15 -4\uff08\u5305\u62ec\uff09\u5230\u7d22\u5f15 -1\uff08\u6392\u9664\uff09\u7684\u9879\u76ee\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;orange&quot;, &quot;kiwi&quot;, &quot;melon&quot;, &quot;mango&quot;]\nprint(thislist[-4:-1])\n\n#\u901a\u8fc7\u7d22\u5f15\u66f4\u6539\u9879\u76ee\u503c\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nthislist[1] = &quot;mango&quot;\nprint(thislist)\n\n#\u4f7f\u7528 for \u5faa\u73af\u904d\u5386\u5217\u8868\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor x in thislist:\n  print(x)\n\n#\u68c0\u67e5\u5217\u8868\u4e2d\u662f\u5426\u5b58\u5728 \u201capple\u201d\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nif &quot;apple&quot; in thislist:\n  print(&quot;Yes, &#039;apple&#039; is in the fruits list&quot;)\n\n#\u5982\u9700\u786e\u5b9a\u5217\u8868\u4e2d\u6709\u591a\u5c11\u9879\uff0c\u8bf7\u4f7f\u7528 len() \u65b9\u6cd5\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nprint(len(thislist))\n\n#\u4f7f\u7528 append() \u65b9\u6cd5\u8ffd\u52a0\u9879\u76ee\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nthislist.append(&quot;orange&quot;)\nprint(thislist)\n\n#\u6307\u5b9a\u7684\u7d22\u5f15\u5904\u6dfb\u52a0\u9879\u76ee\uff0c\u8bf7\u4f7f\u7528 insert() \u65b9\u6cd5\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nthislist.insert(1, &quot;orange&quot;)\nprint(thislist)\n\n#remove() \u65b9\u6cd5\u5220\u9664\u6307\u5b9a\u7684\u9879\u76ee\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nthislist.remove(&quot;banana&quot;)\nprint(thislist)\n\n#pop() \u65b9\u6cd5\u5220\u9664\u6307\u5b9a\u7684\u7d22\u5f15\uff08\u5982\u679c\u672a\u6307\u5b9a\u7d22\u5f15\uff0c\u5219\u5220\u9664\u6700\u540e\u4e00\u9879\uff09\uff1a\n#\u8fd9\u4e2a\u5176\u5b9e\u53eb \u5f39\u51fa \u5220\u9664\u539f\u5217\u8868\u9879 \u5e76\u8fd4\u56de\u5220\u9664\u9879\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nthislist.pop()\nprint(thislist)\n\n#del \u5173\u952e\u5b57\u5220\u9664\u6307\u5b9a\u7684\u7d22\u5f15\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\ndel thislist[0]\nprint(thislist)\n\n#del \u5173\u952e\u5b57\u4e5f\u80fd\u5b8c\u6574\u5730\u5220\u9664\u5217\u8868\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\ndel thislist\n\n#clear() \u65b9\u6cd5\u6e05\u7a7a\u5217\u8868\uff1a\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nthislist.clear()\nprint(thislist)\n\n#\u4f7f\u7528 copy() \u65b9\u6cd5\u6765\u590d\u5236\u5217\u8868\uff1a\n#\u8fd9\u79cd\u65b9\u6cd5 \u662f\u771f\u590d\u5236\u4e86\u4e00\u4efd\uff0c\u800c\u4e0d\u662f\u539f\u6765\u7684\u7d22\u5f15  \u4e5f\u53eb\u6df1\u62f7\u8d1d\n#\u5982\u679c\u4f7f\u7528 list2 = list1 \u6765\u590d\u5236\u5217\u8868 \u5f97\u5230\u7684\u4ec5\u4ec5\u662f\u7d22\u5f15\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nmylist = thislist.copy()\nprint(mylist)\nprint(id(mylist))\nprint(id(thislist))\n\n#\u5236\u4f5c\u526f\u672c\u7684\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u5185\u5efa\u7684\u65b9\u6cd5 list()\u3002\n#\u8fd9\u79cd\u4e5f\u662f\u6df1\u62f7\u8d1d\nthislist = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nmylist = list(thislist)\nprint(mylist)\nprint(id(thislist))\nprint(id(mylist))\n\n#\u4f7f\u7528 + \u8fd0\u7b97\u7b26 \u5408\u5e76\u4e24\u4e2a\u5217\u8868\nlist1 = [&quot;a&quot;, &quot;b&quot; , &quot;c&quot; , 3]\nlist2 = [1, 2, 3, &#039;a&#039;]\nlist3 = list1 + list2\nprint(list3)\n\n#\u628a list2 \u8ffd\u52a0\u5230 list1 \u4e2d\uff1a\nlist1 = [&quot;a&quot;, &quot;b&quot; , &quot;c&quot;]\nlist2 = [1, 2, 3]\nfor x in list2:\n  list1.append(x)\nprint(list1)\n\n#\u4f7f\u7528 extend() \u65b9\u6cd5\u5c06 list2 \u6dfb\u52a0\u5230 list1 \u7684\u672b\u5c3e\uff1a\nlist1 = [&quot;a&quot;, &quot;b&quot; , &quot;c&quot;]\nlist2 = [1, 2, 3]\nlist1.extend(list2)\nprint(list1)\n\n#\u4f7f\u7528 list() \u6784\u9020\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u65b0\u5217\u8868\u3002\nthislist = list((&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)) # \u8bf7\u6ce8\u610f\u53cc\u62ec\u53f7\nprint(thislist)\n<\/code><\/pre>\n<h5>\u5143\u7ec4\uff08Tuple\uff09<\/h5>\n<h6>\u5143\u7ec4\u662f\u6709\u5e8f\u4e14\u4e0d\u53ef\u66f4\u6539\u7684\u96c6\u5408\u3002\u5728 Python \u4e2d\uff0c\u5143\u7ec4\u662f\u7528\u5706\u62ec\u53f7\u7f16\u5199\u7684\u3002<\/h6>\n<pre><code class=\"language-python\">thistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\nprint(thistuple)\n\n#\u6253\u5370\u5143\u7ec4\u4e2d\u7684\u7b2c\u4e8c\u4e2a\u9879\u76ee\uff1a\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\nprint(thistuple[1])\n\n#\u6253\u5370\u5143\u7ec4\u7684\u6700\u540e\u4e00\u4e2a\u9879\u76ee\uff1a\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\nprint(thistuple[-1])\n\n#\u8fd4\u56de\u5143\u7ec4\u7684 \u4e0b\u6807\u4e3a 2 3 4 \u7684\u5143\u7d20 \u5305\u524d\u4e0d\u5305\u540e\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;orange&quot;, &quot;kiwi&quot;, &quot;melon&quot;, &quot;mango&quot;)\nprint(thistuple[2:5])\n\n#\u8fd4\u56de\u4ece\u7d22\u5f15 -4\uff08\u5305\u62ec\uff09\u5230\u7d22\u5f15 -1\uff08\u6392\u9664\uff09\u7684\u9879\u76ee\uff1a\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;orange&quot;, &quot;kiwi&quot;, &quot;melon&quot;, &quot;mango&quot;)\nprint(thistuple[-4:-1])\n\n#\u5982\u679c\u60f3\u66f4\u6539\u5143\u7ec4 \u53ef\u4ee5\u5148\u8f6c\u6362\u6210list \u6539\u5b8c\u518d\u8f6c\u56de\u6765\nx = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\ny = list(x)\ny[1] = &quot;kiwi&quot;\nx = tuple(y)\nprint(x)\n\n#\u4f7f\u7528 for \u5faa\u73af\u904d\u5386\u5143\u7ec4\u9879\u76ee\u3002\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\nfor x in thistuple:\n  print(x)\n\n#\u68c0\u67e5\u5143\u7ec4\u4e2d\u662f\u5426\u5b58\u5728 &quot;apple&quot;\uff1a\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\nif &quot;apple&quot; in thistuple:\n  print(&quot;Yes, &#039;apple&#039; is in the fruits tuple&quot;)\n\n#\u6253\u5370\u5143\u7ec4\u4e2d\u7684\u9879\u76ee\u6570\u91cf\uff1alen()\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\nprint(len(thistuple))\n\n#\u5143\u7ec4\u4e00\u65e6\u521b\u5efa\uff0c\u60a8\u5c31\u65e0\u6cd5\u5411\u5176\u6dfb\u52a0\u9879\u76ee\u3002\u5143\u7ec4\u662f\u4e0d\u53ef\u6539\u53d8\u7684\u3002\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\nthistuple[3] = &quot;orange&quot; # \u4f1a\u5f15\u53d1\u9519\u8bef\nprint(thistuple)\n\n#\u5355\u9879\u5143\u7ec4\uff0c\u522b\u5fd8\u4e86\u9017\u53f7\uff1a\nthistuple = (&quot;apple&quot;,)\nprint(type(thistuple))\n\n#\u4e0d\u662f\u5143\u7ec4\nthistuple = (&quot;apple&quot;)\nprint(type(thistuple))\n\n#del \u5173\u952e\u5b57\u53ef\u4ee5\u5b8c\u5168\u5220\u9664\u5143\u7ec4\uff1a\nthistuple = (&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)\ndel thistuple\nprint(thistuple) # \u8fd9\u4f1a\u5f15\u53d1\u9519\u8bef\uff0c\u56e0\u4e3a\u5143\u7ec4\u5df2\u4e0d\u5b58\u5728\u3002\n\n#\u4f7f\u7528 + \u8fd0\u7b97\u7b26 \u5408\u5e76\u4e24\u4e2a\u5143\u7ec4\ntuple1 = (&quot;a&quot;, &quot;b&quot; , &quot;c&quot;)\ntuple2 = (1, 2, 3)\ntuple3 = tuple1 + tuple2\nprint(tuple3)\n\n#\u4f7f\u7528 tuple() \u6784\u9020\u51fd\u6570\u6765\u521b\u5efa\u5143\u7ec4\u3002\nthistuple = tuple((&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)) # \u8bf7\u6ce8\u610f\u53cc\u62ec\u53f7\nprint(thistuple)\n<\/code><\/pre>\n<h5>\u96c6\u5408\uff08Set\uff09<\/h5>\n<h6>\u96c6\u5408\u662f\u65e0\u5e8f\u548c\u65e0\u7d22\u5f15\u7684\u96c6\u5408\u3002\u5728 Python \u4e2d\uff0c\u96c6\u5408\u7528\u82b1\u62ec\u53f7\u7f16\u5199\u3002<\/h6>\n<h6>\u96c6\u5408\u4e00\u65e6\u521b\u5efa\uff0c\u60a8\u5c31\u65e0\u6cd5\u66f4\u6539\u9879\u76ee\uff0c\u4f46\u662f\u60a8\u53ef\u4ee5\u6dfb\u52a0\u65b0\u9879\u76ee\u3002<\/h6>\n<pre><code class=\"language-python\">#\u521b\u5efa\u96c6\u5408\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nprint(thisset)\n\n#\u904d\u5386\u96c6\u5408\uff0c\u5e76\u6253\u5370\u503c\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nfor x in thisset:\n  print(x)\n\n#\u68c0\u67e5 set \u4e2d\u662f\u5426\u5b58\u5728 \u201cbanana\u201d\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nprint(&quot;banana&quot; in thisset)\n\n#\u5c06\u4e00\u4e2a\u9879\u6dfb\u52a0\u5230\u96c6\u5408\uff0c\u8bf7\u4f7f\u7528 add() \u65b9\u6cd5\u3002\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nthisset.add(&quot;orange&quot;)\nprint(thisset)\n\n#\u4f7f\u7528 update() \u65b9\u6cd5\u5c06\u591a\u4e2a\u9879\u6dfb\u52a0\u5230\u96c6\u5408\u4e2d\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nthisset.update([&quot;orange&quot;, &quot;mango&quot;, &quot;grapes&quot;])\nprint(thisset)\n\n#\u8981\u786e\u5b9a\u96c6\u5408\u4e2d\u6709\u591a\u5c11\u9879\uff0c\u8bf7\u4f7f\u7528 len() \u65b9\u6cd5\u3002\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nprint(len(thisset))\n\n#\u4f7f\u7528 remove() \u65b9\u6cd5\u6765\u5220\u9664 \u201cbanana\u201d\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nthisset.remove(&quot;banana&quot;)\nprint(thisset)\n\n#\u4f7f\u7528 discard() \u65b9\u6cd5\u6765\u5220\u9664 \u201cbanana\u201d\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nthisset.discard(&quot;banana&quot;)\nprint(thisset)\n\n#\u4f7f\u7528 pop() \u65b9\u6cd5\u5220\u9664\u6700\u540e\u4e00\u9879\uff1a\n#pop() \u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u662f\u88ab\u5220\u9664\u7684\u9879\u76ee\u3002\n#set \u662f\u65e0\u5e8f\u7684\uff0c\u56e0\u6b64\u60a8\u4e0d\u4f1a\u77e5\u9053\u88ab\u5220\u9664\u7684\u662f\u4ec0\u4e48\u9879\u76ee\u3002\n#\u8fd9\u4e2a\u53ef\u4ee5\u7528\u4f5c\u968f\u673a\u53d6\u503c\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nx = thisset.pop()\nprint(x)\nprint(thisset)\n\n#clear() \u65b9\u6cd5\u6e05\u7a7a\u96c6\u5408\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\nthisset.clear()\nprint(thisset)\n\n#del \u5f7b\u5e95\u5220\u9664\u96c6\u5408\uff1a\nthisset = {&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;}\ndel thisset\nprint(thisset) #\u8fd9\u91cc\u4f1a\u62a5\u9519\n\n#\u5408\u5e76\u4e24\u4e2a\u96c6\u5408 union() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u65b0\u96c6\u5408\uff0c\u5176\u4e2d\u5305\u542b\u4e24\u4e2a\u96c6\u5408\u4e2d\u7684\u6240\u6709\u9879\u76ee\uff1a\nset1 = {&quot;a&quot;, &quot;b&quot; , &quot;c&quot;}\nset2 = {1, 2, 3}\nset3 = set1.union(set2)\nprint(set3)\n\n#update() \u65b9\u6cd5\u5c06 set2 \u4e2d\u7684\u9879\u76ee\u63d2\u5165 set1 \u4e2d\uff1a\nset1 = {&quot;a&quot;, &quot;b&quot; , &quot;c&quot;}\nset2 = {1, 2, 3}\nset1.update(set2)\nprint(set1)\n\n#\u4f7f\u7528 set() \u6784\u9020\u51fd\u6570\u6765\u521b\u5efa\u96c6\u5408\uff1a\nthisset = set((&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;)) # \u8bf7\u7559\u610f\u8fd9\u4e2a\u53cc\u62ec\u53f7\nprint(thisset)<\/code><\/pre>\n<h5>\u5b57\u5178\uff08Dictionary\uff09<\/h5>\n<h6>\u5b57\u5178\u662f\u4e00\u4e2a\u65e0\u5e8f\u3001\u53ef\u53d8\u548c\u6709\u7d22\u5f15\u7684\u96c6\u5408\u3002\u5728 Python \u4e2d\uff0c\u5b57\u5178\u7528\u82b1\u62ec\u53f7\u7f16\u5199\uff0c\u62e5\u6709\u952e\u548c\u503c\u3002<\/h6>\n<pre><code class=\"language-python\">#\u521b\u5efa\u5e76\u6253\u5370\u5b57\u5178\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nprint(thisdict)\n\n#\u83b7\u53d6 &quot;model&quot; \u952e\u7684\u503c\uff1a\nx = thisdict[&quot;model&quot;]\n\n#\u83b7\u53d6 &quot;model&quot; \u952e\u7684\u503c\uff1a\n#\u8fd8\u6709\u4e00\u4e2a\u540d\u4e3a get() \u7684\u65b9\u6cd5\u4f1a\u7ed9\u4f60\u76f8\u540c\u7684\u7ed3\u679c\uff1a\nx = thisdict.get(&quot;model&quot;)\n\n#\u628a &quot;year&quot; \u6539\u4e3a 2019\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nthisdict[&quot;year&quot;] = 2019\n\n#\u4f7f\u7528 for \u5faa\u73af\u904d\u5386\u5b57\u5178\u3002\n#\u8fd9\u91cc\u53ea\u6253\u5370\u51fa\u6765\u5f97\u662f\u5065\nfor x in thisdict:\n  print(x)\n\n#\u9010\u4e2a\u6253\u5370\u5b57\u5178\u4e2d\u7684\u6240\u6709\u503c\uff1a\nfor x in thisdict:\n  print(thisdict[x])\n\n#\u8fd8\u53ef\u4ee5\u4f7f\u7528 values() \u51fd\u6570\u8fd4\u56de\u5b57\u5178\u7684\u503c\uff1a\nfor x in thisdict.values():\n  print(x)\n\n#\u901a\u8fc7\u4f7f\u7528 items() \u51fd\u6570\u904d\u5386\u952e\u548c\u503c\uff1a\nfor x, y in thisdict.items():\n  print(x, y)\n\n#\u68c0\u67e5\u5b57\u5178\u4e2d\u662f\u5426\u5b58\u5728 &quot;model&quot;\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nif &quot;model&quot; in thisdict:\n  print(&quot;Yes, &#039;model&#039; is one of the keys in the thisdict dictionary&quot;)\n\n#\u8981\u786e\u5b9a\u5b57\u5178\u6709\u591a\u5c11\u9879\u76ee\uff08\u952e\u503c\u5bf9\uff09\uff0c\u8bf7\u4f7f\u7528 len() \u65b9\u6cd5\u3002\nprint(len(thisdict))\n\n#\u6dfb\u52a0\u9879\u76ee \u901a\u8fc7\u4f7f\u7528\u65b0\u7684\u7d22\u5f15\u952e\u5e76\u4e3a\u5176\u8d4b\u503c\uff0c\u53ef\u4ee5\u5c06\u9879\u76ee\u6dfb\u52a0\u5230\u5b57\u5178\u4e2d\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nthisdict[&quot;color&quot;] = &quot;red&quot;\nprint(thisdict)\n\n#pop() \u65b9\u6cd5\u5220\u9664\u5177\u6709\u6307\u5b9a\u952e\u540d\u7684\u9879\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nthisdict.pop(&quot;model&quot;)\nprint(thisdict)\n\n#popitem() \u65b9\u6cd5\u5220\u9664\u6700\u540e\u63d2\u5165\u7684\u9879\u76ee\uff08\u5728 3.7 \u4e4b\u524d\u7684\u7248\u672c\u4e2d\uff0c\u5220\u9664\u968f\u673a\u9879\u76ee\uff09\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nthisdict.popitem()\nprint(thisdict)\n\n#del \u5173\u952e\u5b57\u5220\u9664\u5177\u6709\u6307\u5b9a\u952e\u540d\u7684\u9879\u76ee\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\ndel thisdict[&quot;model&quot;]\nprint(thisdict)\n\n#del \u5173\u952e\u5b57\u4e5f\u53ef\u4ee5\u5b8c\u5168\u5220\u9664\u5b57\u5178\uff1a\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\ndel thisdict\nprint(thisdict) #this \u4f1a\u5bfc\u81f4\u9519\u8bef\uff0c\u56e0\u4e3a &quot;thisdict&quot; \u4e0d\u518d\u5b58\u5728\u3002\n\n#clear() \u5173\u952e\u5b57\u6e05\u7a7a\u5b57\u5178\uff1a\n#\u4ec5\u4ec5\u662f\u6e05\u7a7a \u800c\u4e0d\u5220\u9664\u5b57\u5178\u672c\u8eab\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nthisdict.clear()\nprint(thisdict)\n\n#\u590d\u5236\u5b57\u5178 \u4f7f\u7528 copy() \u65b9\u6cd5\u6765\u590d\u5236\u5b57\u5178\uff1a\n#\u771f\u590d\u5236\u4e86\u4e00\u4e2a\u526f\u672c\uff0c\u6df1\u62f7\u8d1d \u800c\u4e0d\u662f\u7b80\u5355\u7684\u62ff\u5230\u4e86\u5185\u5b58\u7d22\u5f15\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nmydict = thisdict.copy()\nprint(id(mydict))\nprint(id(thisdict))\nprint(mydict)\n\n#\u5236\u4f5c\u526f\u672c\u7684\u53e6\u4e00\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u5185\u5efa\u65b9\u6cd5 dict()\u3002\n#\u4f7f\u7528 dict() \u65b9\u6cd5\u521b\u5efa\u5b57\u5178\u7684\u526f\u672c\uff1a\n#\u4e24\u6837\u662f\u590d\u5236\u4e86\u526f\u672c\nthisdict =  {\n  &quot;brand&quot;: &quot;Porsche&quot;,\n  &quot;model&quot;: &quot;911&quot;,\n  &quot;year&quot;: 1963\n}\nmydict = dict(thisdict)\nprint(id(mydict))\nprint(id(thisdict))\nprint(mydict)\n\n#\u5d4c\u5957\u5b57\u5178\n#\u8bcd\u5178\u4e5f\u53ef\u4ee5\u5305\u542b\u8bb8\u591a\u8bcd\u5178\uff0c\u8fd9\u88ab\u79f0\u4e3a\u5d4c\u5957\u8bcd\u5178\u3002\n#\u76f8\u5f53\u4e8e\u4e8c\u7ea7\u5b57\u5178\nmyfamily = {\n  &quot;child1&quot; : {\n    &quot;name&quot; : &quot;Phoebe Adele&quot;,\n    &quot;year&quot; : 2002\n  },\n  &quot;child2&quot; : {\n    &quot;name&quot; : &quot;Jennifer Katharine&quot;,\n    &quot;year&quot; : 1996\n  },\n  &quot;child3&quot; : {\n    &quot;name&quot; : &quot;Rory John&quot;,\n    &quot;year&quot; : 1999\n  }\n}\nprint(myfamily)\n\nchild1 = {\n  &quot;name&quot; : &quot;Phoebe Adele&quot;,\n  &quot;year&quot; : 2002\n}\nchild2 = {\n  &quot;name&quot; : &quot;Jennifer Katharine&quot;,\n  &quot;year&quot; : 1996\n}\nchild3 = {\n  &quot;name&quot; : &quot;Rory John&quot;,\n  &quot;year&quot; : 1999\n}\n\nmyfamily = {\n  &quot;child1&quot; : child1,\n  &quot;child2&quot; : child2,\n  &quot;child3&quot; : child3\n}\n\n#\u4e5f\u53ef\u4ee5\u4f7f\u7528 dict() \u6784\u9020\u51fd\u6570\u521b\u5efa\u65b0\u7684\u5b57\u5178\uff1a\nthisdict = dict(brand=&quot;Porsche&quot;, model=&quot;911&quot;, year=1963)\n# \u8bf7\u6ce8\u610f\uff0c\u5173\u952e\u5b57\u4e0d\u662f\u5b57\u7b26\u4e32\u5b57\u9762\u91cf\n# \u8bf7\u6ce8\u610f\uff0c\u4f7f\u7528\u4e86\u7b49\u53f7\u800c\u4e0d\u662f\u5192\u53f7\u6765\u8d4b\u503c\nprint(thisdict)<\/code><\/pre>\n<h5>if else \u8bed\u53e5<\/h5>\n<h6>Python \u652f\u6301\u6765\u81ea\u6570\u5b66\u7684\u5e38\u7528\u903b\u8f91\u6761\u4ef6\uff1a<\/h6>\n<pre><code class=\"language-python\">#\u7b49\u4e8e\uff1aa == b\n#\u4e0d\u7b49\u4e8e\uff1aa != b\n#\u5c0f\u4e8e\uff1aa &lt; b\n#\u5c0f\u4e8e\u7b49\u4e8e\uff1aa &lt;= b\n#\u5927\u4e8e\uff1aa &gt; b\n#\u5927\u4e8e\u7b49\u4e8e\uff1aa &gt;= b\n\na = 66\nb = 200\nif b &gt; a:\n  print(&quot;b is greater than a&quot;)\n\n#elif \u5173\u952e\u5b57\na = 66\nb = 66\nif b &gt; a:\n  print(&quot;b is greater than a&quot;)\nelif a == b:\n  print(&quot;a and b are equal&quot;)\n\n#else \u5173\u952e\u5b57\na = 200\nb = 66\nif b &gt; a:\n  print(&quot;b is greater than a&quot;)\nelif a == b:\n  print(&quot;a and b are equal&quot;)\nelse:\n  print(&quot;a is greater than b&quot;)\n\n#\u7b80\u5199 If \u53ea\u6709\u4e00\u6761\u8bed\u53e5\na = 200\nb = 66\nif a &gt; b: print(&quot;a is greater than b&quot;)\n\n#\u7b80\u5199 If ... else\na = 200\nb = 66\nprint(&quot;A&quot;) if a &gt; b else print(&quot;B&quot;)\n\n#\u8fd8\u53ef\u4ee5\u5728\u540c\u4e00\u884c\u4e0a\u4f7f\u7528\u591a\u4e2a else \u8bed\u53e5\uff1a\n#\u6bd4\u8f83\u5947\u602a\u7684\u8bed\u6cd5\na = 200\nb = 66\nprint(&quot;A&quot;) if a &gt; b else print(&quot;=&quot;) if a == b else print(&quot;B&quot;)\n\n#and \u5173\u952e\u5b57\u662f\u4e00\u4e2a\u903b\u8f91\u8fd0\u7b97\u7b26\uff0c\u7528\u4e8e\u7ec4\u5408\u6761\u4ef6\u8bed\u53e5\uff1a\na = 200\nb = 66\nc = 500\nif a &gt; b and c &gt; a:\n  print(&quot;Both conditions are True&quot;)\n\n#or \u5173\u952e\u5b57\u4e5f\u662f\u903b\u8f91\u8fd0\u7b97\u7b26\uff0c\u7528\u4e8e\u7ec4\u5408\u6761\u4ef6\u8bed\u53e5\uff1a\na = 200\nb = 66\nc = 500\nif a &gt; b or a &gt; c:\n  print(&quot;At least one of the conditions is True&quot;)\n\n#\u5d4c\u5957 If \u53ef\u4ee5\u5728 if \u8bed\u53e5\u4e2d\u5305\u542b if \u8bed\u53e5\uff0c\u8fd9\u79f0\u4e3a\u5d4c\u5957 if \u8bed\u53e5\u3002\n#\u8fd9\u91cc\u8981\u6ce8\u610f\u7f29\u8fdb\nx = 52\nif x &gt; 10:\n  print(&quot;Above ten,&quot;)\n  if x &gt; 20:\n    print(&quot;and also above 20!&quot;)\n  else:\n    print(&quot;but not above 20.&quot;)\n\n#pass \u8bed\u53e5 if \u8bed\u53e5\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u4f46\u662f\u5982\u679c\u60a8\u5904\u4e8e\u67d0\u79cd\u539f\u56e0\u5199\u4e86\u65e0\u5185\u5bb9\u7684 if \u8bed\u53e5\uff0c\u8bf7\u4f7f\u7528 pass \u8bed\u53e5\u6765\u907f\u514d\u9519\u8bef\u3002\na = 66\nb = 200\nif b &gt; a:\n  pass\n<\/code><\/pre>\n<h5>while \u5faa\u73af<\/h5>\n<pre><code class=\"language-python\">i = 1\nwhile i &lt; 7:\n  print(i)\n  i += 1\n\n#break \u8bed\u53e5 \u8df3\u51fa\u5faa\u73af\ni = 1\nwhile i &lt; 7:\n  print(i)\n  if i == 3:\n    break\n  i += 1\n\n#continue \u8bed\u53e5\ni = 0\nwhile i &lt; 7:\n  i += 1\n  if i == 3:\n    continue\n  print(i)\n\n#else \u8bed\u53e5\n#\u901a\u8fc7\u4f7f\u7528 else \u8bed\u53e5\uff0c\u5f53\u6761\u4ef6\u4e0d\u518d\u6210\u7acb\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd0\u884c\u4e00\u6b21\u4ee3\u7801\u5757\uff1a\ni = 1\nwhile i &lt; 6:\n  print(i)\n  i += 1\nelse:\n  print(&quot;i is no longer less than 6&quot;)\n<\/code><\/pre>\n<h5>Python For \u5faa\u73af<\/h5>\n<pre><code class=\"language-python\">#for \u5faa\u73af\u7528\u4e8e\u8fed\u4ee3\u5e8f\u5217\uff08\u5373\u5217\u8868\uff0c\u5143\u7ec4\uff0c\u5b57\u5178\uff0c\u96c6\u5408\u6216\u5b57\u7b26\u4e32\uff09\u3002\n#\u901a\u8fc7\u4f7f\u7528 for \u5faa\u73af\uff0c\u6211\u4eec\u53ef\u4ee5\u4e3a\u5217\u8868\u3001\u5143\u7ec4\u3001\u96c6\u5408\u4e2d\u7684\u6bcf\u4e2a\u9879\u76ee\u7b49\u6267\u884c\u4e00\u7ec4\u8bed\u53e5\u3002\nfruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor x in fruits:\n  print(x)\n\n#\u5faa\u73af\u904d\u5386\u5355\u8bcd &quot;banana&quot; \u4e2d\u7684\u5b57\u6bcd\uff1a\nfor x in &quot;banana&quot;:\n  print(x)\n\n#\u5982\u679c x \u662f &quot;banana&quot;\uff0c\u5219\u9000\u51fa\u5faa\u73af\uff1a\nfruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor x in fruits:\n  print(x)\n  if x == &quot;banana&quot;:\n    break\n\n#\u5f53 x \u4e3a &quot;banana&quot; \u65f6\u9000\u51fa\u5faa\u73af\uff0c\u4f46\u8fd9\u6b21\u5728\u6253\u5370\u4e4b\u524d\u4e2d\u65ad\uff1a\nfruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor x in fruits:\n  if x == &quot;banana&quot;:\n    break\n  print(x)\n\n#\u901a\u8fc7\u4f7f\u7528 continue \u8bed\u53e5\uff0c\u6211\u4eec\u53ef\u4ee5\u505c\u6b62\u5faa\u73af\u7684\u5f53\u524d\u8fed\u4ee3\uff0c\u5e76\u7ee7\u7eed\u4e0b\u4e00\u4e2a\uff1a\nfruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor x in fruits:\n  if x == &quot;banana&quot;:\n    continue\n  print(x)\n\n#range() \u51fd\u6570\n#\u5982\u9700\u5faa\u73af\u4e00\u7ec4\u4ee3\u7801\u6307\u5b9a\u7684\u6b21\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 range() \u51fd\u6570\uff0c\n#\u5982\u9700\u5faa\u73af\u4e00\u7ec4\u4ee3\u7801\u6307\u5b9a\u7684\u6b21\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 range() \u51fd\u6570\uff0c\nfor x in range(10):\n  print(x)\n\n#\u4f7f\u7528\u8d77\u59cb\u53c2\u6570\uff1a\nfor x in range(3, 10):\n  print(x)\n\n#\u4f7f\u7528 3 \u9012\u589e\u5e8f\u5217\uff08\u9ed8\u8ba4\u503c\u4e3a 1\uff09\uff1a\n#\u95f4\u9694\nfor x in range(3, 50, 6):\n  print(x)\n\n#For \u5faa\u73af\u4e2d\u7684 Else\n#for \u5faa\u73af\u4e2d\u7684 else \u5173\u952e\u5b57\u6307\u5b9a\u5faa\u73af\u7ed3\u675f\u65f6\u8981\u6267\u884c\u7684\u4ee3\u7801\u5757\uff1a\n#\u6253\u5370 0 \u5230 9 \u7684\u6240\u6709\u6570\u5b57\uff0c\u5e76\u5728\u5faa\u73af\u7ed3\u675f\u65f6\u6253\u5370\u4e00\u6761\u6d88\u606f\uff1a\nfor x in range(10):\n  print(x)\nelse:\n  print(&quot;Finally finished!&quot;)\n\n#\u5d4c\u5957\u5faa\u73af\n#\u6253\u5370\u6bcf\u4e2a\u6c34\u679c\u7684\u6bcf\u4e2a\u5f62\u5bb9\u8bcd\uff1a\nadj = [&quot;red&quot;, &quot;big&quot;, &quot;tasty&quot;]\nfruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nfor x in adj:\n  for y in fruits:\n    print(x, y)\n\n#pass \u8bed\u53e5\n#for \u8bed\u53e5\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u4f46\u662f\u5982\u679c\u60a8\u5904\u4e8e\u67d0\u79cd\u539f\u56e0\u5199\u4e86\u65e0\u5185\u5bb9\u7684 for \u8bed\u53e5\uff0c\u8bf7\u4f7f\u7528 pass \u8bed\u53e5\u6765\u907f\u514d\u9519\u8bef\u3002\nfor x in [0, 1, 2]:\n  pass\n<\/code><\/pre>\n<h5>Python \u51fd\u6570<\/h5>\n<pre><code class=\"language-python\">def my_function():\n  print(&quot;Hello from a function&quot;)\n\ndef my_function():\n  print(&quot;Hello from a function&quot;)\nmy_function()\n\ndef my_function(fname):\n  print(fname + &quot; Gates&quot;)\nmy_function(&quot;Bill&quot;)\nmy_function(&quot;Steve&quot;)\nmy_function(&quot;Elon&quot;)\n\n#\u51fd\u6570\u9ed8\u8ba4\u503c\ndef my_function(country = &quot;japan&quot;):\n  print(&quot;I am from &quot; + country)\nmy_function(&quot;Sweden&quot;)\nmy_function(&quot;India&quot;)\nmy_function()\nmy_function(&quot;Brazil&quot;)\n\n#\u4ee5 List \u4f20\u53c2\ndef my_function(food):\n  for x in food:\n    print(x)\nfruits = [&quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;]\nmy_function(fruits)\n\n#\u8fd4\u56de\u503c\n#python\u91cc\u53ef\u4ee5\u8fd4\u56de\u591a\u4e2a\u503c\ndef my_function(x):\n  return 5 * x\nprint(my_function(3))\nprint(my_function(5))\nprint(my_function(9))\n\n#\u5173\u952e\u5b57\u53c2\u6570\n#\u8fd9\u6837\u4e0d\u5fc5\u5728\u610f\u53c2\u6570\u7684\u987a\u5e8f\ndef my_function(child3, child2, child1):\n  print(&quot;The youngest child is &quot; + child3)\nmy_function(child1 = &quot;Phoebe&quot;, child2 = &quot;Jennifer&quot;, child3 = &quot;Rory&quot;)\n\n#\u4efb\u610f\u53c2\u6570\u6570\u91cf\n#\u5982\u679c\u53c2\u6570\u6570\u76ee\u672a\u77e5\uff0c\u8bf7\u5728\u53c2\u6570\u540d\u79f0\u524d\u6dfb\u52a0 *\uff1a\ndef my_function(*kids):\n  print(&quot;The youngest child is &quot; + kids[2])\nmy_function(&quot;Phoebe&quot;, &quot;Jennifer&quot;, &quot;Rory&quot;)\n\n#pass \u8bed\u53e5\n#\u51fd\u6570\u5b9a\u4e49\u4e0d\u80fd\u4e3a\u7a7a\uff0c\u4f46\u662f\u5982\u679c\u60a8\u51fa\u4e8e\u67d0\u79cd\u539f\u56e0\u5199\u4e86\u65e0\u5185\u5bb9\u7684\u51fd\u6570\u5b9a\u4e49\uff0c\u8bf7\u4f7f\u7528 pass \u8bed\u53e5\u6765\u907f\u514d\u9519\u8bef\u3002\ndef myfunction:\n  pass\n\n#\u9012\u5f52\u51fd\u6570\ndef tri_recursion(k):\n  if(k&gt;0):\n    result = k+tri_recursion(k-1)\n    print(result)\n  else:\n    result = 0\n  return result\n\ntri_recursion(6)\n<\/code><\/pre>\n<h5>Python Lambda\u8868\u8fbe\u5f0f<\/h5>\n<h6>lambda \u51fd\u6570\u662f\u4e00\u79cd\u5c0f\u7684\u533f\u540d\u51fd\u6570\u3002<\/h6>\n<h6>lambda \u51fd\u6570\u53ef\u63a5\u53d7\u4efb\u610f\u6570\u91cf\u7684\u53c2\u6570\uff0c\u4f46\u53ea\u80fd\u6709\u4e00\u4e2a\u8868\u8fbe\u5f0f<\/h6>\n<h6>\u8bed\u6cd5: lambda arguments : expression<\/h6>\n<pre><code class=\"language-python\">#\u4e00\u4e2a lambda \u51fd\u6570\uff0c\u5b83\u628a\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\u7684\u6570\u5b57\u52a0 10\uff0c\u7136\u540e\u6253\u5370\u7ed3\u679c\nx = lambda a : a + 10\nprint(x(5)) #15\n\n#\u4e00\u4e2a lambda \u51fd\u6570\uff0c\u5b83\u628a\u53c2\u6570 a \u4e0e\u53c2\u6570 b \u76f8\u4e58\u5e76\u6253\u5370\u7ed3\u679c\uff1a\nx = lambda a, b : a * b\nprint(x(5, 6))\n\n#\u4e00\u4e2a lambda \u51fd\u6570\uff0c\u5b83\u628a\u53c2\u6570 a\u3001b \u548c c \u76f8\u52a0\u5e76\u6253\u5370\u7ed3\u679c\uff1a\nx = lambda a, b, c : a + b + c\nprint(x(5, 6, 2))\n\n# lambda \u7528\u4f5c\u53e6\u4e00\u4e2a\u51fd\u6570\u5185\u7684\u533f\u540d\u51fd\u6570\u65f6\ndef myfunc(n):\n  return lambda a : a * n\n#\u8fd9\u91cc\u6709\u70b9\u4e0d\u597d\u7406\u89e3 \u8fd9\u91cc\u662f\u8fd4\u56de\u4e86\u4e00\u4e2alambda\u8868\u8fbe\u5f0f\nmydoubler = myfunc(2)\n#\u8fd9\u91cc\u662f\u8c03\u7528\u8fd4\u56de\u7684lambda\u8868\u8fbe\u5f0f\nprint(mydoubler(11))    #22\n\n#\u9ad8\u7ea7\u70b9\u7684\u51fd\u6570\u5185\u90e8\u4f7f\u7528lambda\ndef myfunc(n):\n  return lambda a : a * n\n\nmydoubler = myfunc(2)\nmytripler = myfunc(3)\n\nprint(mydoubler(11))\nprint(mytripler(11))\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>helloWorld print(&#039;Hello World&#039;) Python\u57fa\u7840 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":35,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":317,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/posts\/272\/revisions\/317"}],"wp:attachment":[{"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/669082.xyz\/index.php\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}