{"id":338,"date":"2025-01-11T08:18:00","date_gmt":"2025-01-11T00:18:00","guid":{"rendered":"http:\/\/sqtcw.cn\/?p=338"},"modified":"2025-01-11T08:18:00","modified_gmt":"2025-01-11T00:18:00","slug":"python%e5%9f%ba%e6%9c%ac%e8%af%ad%e6%b3%95%e5%92%8c%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"http:\/\/www.cnitw.com\/?p=338","title":{"rendered":"python\u57fa\u672c\u8bed\u6cd5\u548c\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"\n<p>\u4ee5\u4e0b\u662f\u5173\u4e8e Python \u8bed\u6cd5\u548c\u6570\u636e\u7c7b\u578b\u7684\u4ecb\u7ecd\uff1a<br> <br>\u4e00\u3001Python \u8bed\u6cd5\u7279\u70b9<br> <br>1.\u00a0\u7f29\u8fdb<br> <br>&#8211; Python \u4f7f\u7528\u7f29\u8fdb\u6765\u8868\u793a\u4ee3\u7801\u5757\uff0c\u800c\u4e0d\u662f\u50cf\u5176\u4ed6\u8bed\u8a00\u4f7f\u7528\u82b1\u62ec\u53f7\u3002\u901a\u5e38\u4f7f\u7528\u56db\u4e2a\u7a7a\u683c\u4f5c\u4e3a\u4e00\u7ea7\u7f29\u8fdb\u3002<br>&#8211; \u4f8b\u5982\uff1a<br> <br>python<br> <br>if True:<br>     print(&#8220;This is a true statement.&#8221;)<br>else:<br>     print(&#8220;This is a false statement.&#8221;)<br>\u00a0<br>2.\u00a0\u6ce8\u91ca<br> <br>&#8211; \u5355\u884c\u6ce8\u91ca\u4f7f\u7528 \u00a0#\u00a0\u3002<br>&#8211; \u591a\u884c\u6ce8\u91ca\u53ef\u4ee5\u4f7f\u7528\u4e09\u4e2a\u5355\u5f15\u53f7\u6216\u4e09\u4e2a\u53cc\u5f15\u53f7\u5305\u88f9\u8d77\u6765\u3002<br>&#8211; \u793a\u4f8b\uff1a<br> <br>python<br> <br># \u8fd9\u662f\u5355\u884c\u6ce8\u91ca<br>&#8221;&#8217;<br>\u8fd9\u662f\u591a\u884c\u6ce8\u91ca<br>&#8221;&#8217;<br>\u00a0<br>3.\u00a0\u53d8\u91cf\u5b9a\u4e49<br> <br>&#8211; \u53d8\u91cf\u65e0\u9700\u58f0\u660e\u7c7b\u578b\uff0c\u76f4\u63a5\u8d4b\u503c\u5373\u53ef\u521b\u5efa\u3002<br>&#8211; \u4f8b\u5982\uff1a<br> <br>python<br> <br>x = 10<br>y = &#8220;Hello, World!&#8221;<br>z = 3.14<br>\u00a0<br> <br>\u4e8c\u3001Python \u6570\u636e\u7c7b\u578b<br> <br>1.\u00a0\u6570\u5b57\u7c7b\u578b<br> <br>&#8211; \u6574\u6570\uff08int\uff09\uff1a\u53ef\u4ee5\u662f\u4efb\u610f\u5927\u5c0f\u7684\u6574\u6570\uff0c\u4f8b\u5982 \u00a0a = 100\u00a0\u3002<br>&#8211; \u6d6e\u70b9\u6570\uff08float\uff09\uff1a\u5e26\u6709\u5c0f\u6570\u70b9\u7684\u6570\u5b57\uff0c\u4f8b\u5982 \u00a0b = 3.14\u00a0\u3002<br>&#8211; \u590d\u6570\uff08complex\uff09\uff1a\u7531\u5b9e\u6570\u90e8\u5206\u548c\u865a\u6570\u90e8\u5206\u7ec4\u6210\uff0c\u4f8b\u5982 \u00a0c = 3 + 4j\u00a0\u3002<br>2.\u00a0\u5b57\u7b26\u4e32\u7c7b\u578b\uff08str\uff09<br> <br>&#8211; \u7528\u5355\u5f15\u53f7\u3001\u53cc\u5f15\u53f7\u6216\u4e09\u5f15\u53f7\u5305\u88f9\u8d77\u6765\u7684\u5b57\u7b26\u5e8f\u5217\u3002<br>&#8211; \u4f8b\u5982\uff1a<br> <br>python<br> <br>s1 = &#8216;Hello&#8217;<br>s2 = &#8220;World&#8221;<br>s3 = &#8221;&#8217;This is a long string.&#8221;&#8217;<br>\u00a0<br> <br>&#8211; \u5b57\u7b26\u4e32\u652f\u6301\u7d22\u5f15\u548c\u5207\u7247\u64cd\u4f5c\u3002<br>3.\u00a0\u5217\u8868\uff08list\uff09<br> <br>&#8211; \u662f\u4e00\u79cd\u53ef\u53d8\u5e8f\u5217\uff0c\u53ef\u4ee5\u5305\u542b\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\u3002<br>&#8211; \u4f8b\u5982\uff1a<br> <br>python<br> <br>my_list = [1, &#8216;two&#8217;, 3.0]<br>\u00a0<br> <br>&#8211; \u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u5143\u7d20\u3001\u5207\u7247\u3001\u6dfb\u52a0\u6216\u5220\u9664\u5143\u7d20\u7b49\u64cd\u4f5c\u3002<br>4.\u00a0\u5143\u7ec4\uff08tuple\uff09<br> <br>&#8211; \u662f\u4e00\u79cd\u4e0d\u53ef\u53d8\u5e8f\u5217\uff0c\u53ef\u4ee5\u5305\u542b\u4e0d\u540c\u7c7b\u578b\u7684\u5143\u7d20\u3002<br>&#8211; \u4f8b\u5982\uff1a<br> <br>python<br> <br>my_tuple = (1, &#8216;two&#8217;, 3.0)<br>\u00a0<br> <br>&#8211; \u5143\u7ec4\u4e00\u65e6\u521b\u5efa\uff0c\u5176\u5143\u7d20\u4e0d\u80fd\u88ab\u4fee\u6539\u3002<br>5.\u00a0\u96c6\u5408\uff08set\uff09<br> <br>&#8211; \u662f\u4e00\u7ec4\u65e0\u5e8f\u7684\u3001\u4e0d\u91cd\u590d\u7684\u5143\u7d20\u3002<br>&#8211; \u4f8b\u5982\uff1a<br> <br>python<br> <br>my_set = {1, 2, 3}<br>\u00a0<br> <br>&#8211; \u53ef\u4ee5\u8fdb\u884c\u96c6\u5408\u8fd0\u7b97\uff0c\u5982\u5e76\u96c6\u3001\u4ea4\u96c6\u3001\u5dee\u96c6\u7b49\u3002<br>6.\u00a0\u5b57\u5178\uff08dict\uff09<br> <br>&#8211; \u662f\u4e00\u79cd\u6620\u5c04\u7c7b\u578b\uff0c\u7531\u952e\u503c\u5bf9\u7ec4\u6210\u3002<br>&#8211; \u4f8b\u5982\uff1a<br> <br>python<br> <br>my_dict = {&#8216;name&#8217;: &#8216;John&#8217;, &#8216;age&#8217;: 30}<br>\u00a0<br> <br>&#8211; \u901a\u8fc7\u952e\u6765\u8bbf\u95ee\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u662f\u5173\u4e8e Python \u8bed\u6cd5\u548c\u6570\u636e\u7c7b\u578b\u7684\u4ecb\u7ecd\uff1a \u4e00\u3001Python \u8bed\u6cd5\u7279\u70b9 1.\u00a0\u7f29\u8fdb &#8211; Python \u4f7f\u7528\u7f29\u8fdb\u6765\u8868\u793a\u4ee3\u7801\u5757\uff0c\u800c\u4e0d\u662f\u50cf\u5176\u4ed6\u8bed\u8a00\u4f7f\u7528\u82b1\u62ec\u53f7\u3002\u901a\u5e38\u4f7f\u7528\u56db\u4e2a\u7a7a\u683c\u4f5c\u4e3a\u4e00\u7ea7\u7f29\u8fdb\u3002&#8211; \u4f8b\u5982\uff1a python if True: print(&#8220;This is a true statement.&#8221;)else: print(&#8220;This is a false statement.&#8221;)\u00a02.\u00a0\u6ce8\u91ca &#8211; \u5355\u884c\u6ce8\u91ca\u4f7f\u7528 \u00a0#\u00a0\u3002&#8211; \u591a\u884c\u6ce8\u91ca\u53ef\u4ee5\u4f7f\u7528\u4e09\u4e2a\u5355\u5f15\u53f7\u6216\u4e09\u4e2a\u53cc\u5f15\u53f7\u5305\u88f9\u8d77\u6765\u3002&#8211; \u793a\u4f8b\uff1a python #&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-338","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=338"}],"version-history":[{"count":0,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/338\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}