{"id":171,"date":"2020-05-15T00:28:06","date_gmt":"2020-05-14T16:28:06","guid":{"rendered":"https:\/\/www.stusc.com\/?p=171"},"modified":"2020-05-15T00:28:06","modified_gmt":"2020-05-14T16:28:06","slug":"python%e5%ad%a6%e4%b9%a0%e6%89%93%e5%8d%a1%ef%bc%88%e4%b8%89%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.stusc.com\/?p=171","title":{"rendered":"Python\u5b66\u4e60\u6253\u5361\uff08\u4e09\uff09"},"content":{"rendered":"\n<p>\u4f7f\u7528&#8221;&#8217;str&#8221;&#8217;\u6765\u683c\u5f0f\u5316\u8de8\u884c\u5b57\u4e32<br>\u4f7f\u7528len(str)\u6765\u83b7\u53d6\u5b57\u7b26\u957f\u5ea6<br>\u4f7f\u7528abs(int)\u6765\u83b7\u53d6\u6570\u503c\u7684\u7edd\u5bf9\u503c<\/p>\n\n\n\n<p>if \u6761\u4ef6(\u771f):\u771f\u7ed3\u679c<br>else (\u5047)\uff1a\u5047\u7ed3\u679c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 2020\/04\/19 \u6d4b\u8bd5\u5b57\u7b26\u5904\u7406\nTXT = \"\u5728\u6587\u4ef6\u5934\u52a0\u4e86'# coding:utf-8'\u540e\u771f\u7684\u53ef\u4ee5\u6b63\u5e38\u663e\u793a\u6c49\u5b57\u4e86\u5417\uff1f\"  #\u901a\u8fc7'# coding:utf-8'\u683c\u5f0f\u5316\u6587\u6863\u7f16\u7801\nprint(TXT)\n#\u4f7f\u7528\u2018\u2018\u2018\u2019\u2019\u2019\u5b9e\u73b0\u957f\u5b57\u7b26\u4e32\u5904\u7406\uff0c\u73b0\u5728\u6d4b\u8bd5\u4e00\u4e0b\u591a\u884c\u8f93\u51fa\nlongstr = '''\u8fd9\u662f\u4e00\u4e2a\u591a\u884c\u7684\u6587\u672c\u663e\u793a\u793a\u4f8b\uff0c\u5f53\u524d\u662f\u7b2c\u4e00\u884c\n\u4f46\u662f\u4e3a\u4ec0\u4e48\u4e0d\u7528\u6362\u884c\u7b26\u6765\u6362\u884c\u5462\uff1f\n\u5b83\u4eec\u7684\u533a\u522b\u662f\u4ec0\u4e48\u5462\uff1f'''\nprint(longstr)\n\"This is a cat: \\N{Cat}\"  #\u5443\uff0c'\\N{Cat}'\u8fd9\u4e2a\u7f16\u7801\u6211\u662f\u4e0d\u61c2\uff0c\u7eaf\u6284\u5199\u6d4b\u8bd5\nprint(\"This is a cat: \\N{Cat}\")\n\nstrlen = len(TXT) #len()\u6c42\u5b57\u4e32\u957f\u5ea6\nprint(strlen)\nprint(TXT&#091;34])\n\n# 2020\/04\/20 \u6d4b\u8bd5if\u8bed\u53e5\na = abs(12) #abs()\u6c42\u7edd\u5bf9\u503c\nb = abs(-12)\nif a == b:print('a = b') \nelse:\n    print(\"a &lt;&gt; b\")\n\n#2020\/04\/26 \nx = bytearray(b\"Hello World!\") #\u5f53x\u4e3abytearray\u7c7b\u578b\u65f6\uff0cx&#091;1]\u548cx&#091;-1]\u503c\u4e3aASCII\u7801\u503c\n# x = \"Hello World!\"\n# x&#091;5] = \"-\"\nn = len(x)\nx&#091;5] = ord(b\"-\")\nprint (n)\nprint (x)\nprint (n,x)\nprint (x&#091;1])\nprint (x&#091;-1])\nprint (x&#091;1],x&#091;-1])\n\n2020\/04\/28 \u6d4b\u8bd5\u5207\u7247\u64cd\u4f5c\nstr_url = \"https:\/\/www.stusc.com\/docs\/python382\"\nstr_len = len(str_url)\nprint(str_len)\nprint(str_url&#091;:])\nprint(str_url&#091;8:])\nprint(str_url&#091;8:str_len])\nprint(str_url&#091;:str_len])\n\n# 2020\/04\/29 \u6d4b\u8bd5\u5207\u7247\u7684\u6b65\u8fdb &#091;x:y:z]xyz\u5747\u4e3a\u6574\u578b\nnumbers = &#091;0,1, 2, 3, 4, 5, 6, 7, 8, 9]\nprint (numbers&#091;1:10:1],numbers&#091;0::1],numbers&#091;:-1:1],numbers&#091;::2],numbers&#091;::3],numbers&#091;::4],numbers&#091;2:8:2])\n\n# 2020\/05\/01 \u6d4b\u8bd5\u6587\u4ef6\u64cd\u4f5c\nof = open('README.md')\nof.write(\"Hello World!\\nThis's my first using FileOpration.\\nThis's 1st line.\")\nof.close()\nof = open('README.md','a')\nof.write(\" # IS this a new line?\")\nof.close()\nof = open('README.md','a')\nof.write(\"\\n# This's a new line.\")\nof.close()\nof = open('README.md','r')\nprint(of.read())\nof.close()\n\n# 2020\/05\/05 \u6d4b\u8bd5\u5e8f\u5217\u76f8\u52a0\nof = open('README.md','a')\nof.write(\"\\n# 2020\/05\/05 \u6d4b\u8bd5\u5e8f\u5217\u76f8\u52a0 \u5b9e\u6d4b\u5b57\u7b26\u4e32\u53ef\u4ee5\u81ea\u7531\u52a0\u51cf\uff0c\u4f46\u5b57\u7b26\u4e32\u65e0\u6cd5\u4e0e\u5b57\u7b26\u4e32\u8fdb\u884c\u76f8\u52a0\")\nof.close()\nof = open('README.md','a')\nof.write(\"\\n# \u6d4b\u8bd5\u5e8f\u5217\u76f8\u4e58 \u5b9e\u6d4b\u5b57\u7b26\u4e32\u53ef\u4ee5\u81ea\u7531\u52a0\u51cf\uff0c\u4f46\u5b57\u7b26\u4e32\u65e0\u6cd5\u4e0e\u5b57\u7b26\u4e32\u8fdb\u884c\u76f8\u52a0\")\nof.close()\nof = open('README.md','a')\nof.write(\"\\n# \u901a\u8fc7\u5b57\u7b26\u4e32\u8fd0\u7b97\u7ed8\u5236\u4e00\u4e2a\u6587\u5b57\u76d2\")\nof.close()\n\na1 = &#091;'Hello ']\na2 = &#091;'World!']\nn1 = &#091;1,2,3]\nprint(a1,a2,n1) #\u8f93\u51fa\u7ed3\u679c\uff1a&#091;'Hello '] &#091;'World!'] &#091;1, 2, 3]\nprint(a1+a2)    #\u8f93\u51fa\u7ed3\u679c\uff1a&#091;'Hello ', 'World!']\nprint(a1+n1)    #\u8f93\u51fa\u7ed3\u679c\uff1a&#091;'Hello ', 1, 2, 3]\nprint('Hello ' + 'World!')  #\u8f93\u51fa\u7ed3\u679c\uff1aHello World!\nprint('Hello ' + a2)    #\u7ed3\u679c\u62a5\u9519\uff1acan only concatenate str (not \"list\") to str\nprint('Hello '+ 1)  #\u7ed3\u679c\u62a5\u9519\uff1acan only concatenate str (not \"int\") to str\nprint(&#091;1,2,3] + 'Hello ')   #\u7ed3\u679c\u62a5\u9519\uff1acan only concatenate list (not \"str\") to list\nprint(a1 * 2)   #\u8f93\u51fa\u7ed3\u679c\uff1a&#091;'Hello ', 'Hello ']\nprint(n1*2)  #\u8f93\u51fa\u7ed3\u679c\uff1a&#091;1, 2, 3, 1, 2, 3]\nprint('Hello '*2)    #\u8f93\u51fa\u7ed3\u679c\uff1aHello Hello \nprint(&#091; ]*10)   #\u8f93\u51fa\u7ed3\u679c\uff1a&#091;]\nprint(&#091;None]*10)    #\u8f93\u51fa\u7ed3\u679c\uff1a&#091;None, None, None, None, None, None, None, None, None, None]\n\nsentence = input(\"Sentence: \") \n# sentence = \"This's my test program!\"\nscreen_width = 80\ntext_width = len(sentence)\nbox_width = text_width + 4\nleft_margin = (screen_width - box_width) \/\/ 2\nprint()\nprint(' ' * left_margin + '+' + '-' * (box_width-2) + '+')\nprint(' ' * left_margin + '| ' + ' ' * (text_width) + ' |')\nprint(' ' * left_margin + '| ' + sentence + ' |')\nprint(' ' * left_margin + '| ' + ' ' * (text_width) + ' |')\nprint(' ' * left_margin + '+' + '-' * (box_width-2) + '+')\nprint()\n\n# 2020\/05\/10 \u6210\u5458\u8d44\u683c\nof = open('README.md','a')\nof.write('''\\n\\n# 2020\/05\/10 \u9a8c\u8bc1\u6210\u5458\u8d44\u683c \u5373 in\u8fd0\u7b97\u7b26,\u8fd0\u7b97\u7b26in\u68c0\u67e5\u3002\n\u6307\u5b9a\u7684\u5bf9\u8c61\u662f\u5426\u662f\u5e8f\u5217\uff08\u6216\u5176\u4ed6\u96c6\u5408\uff09\u7684\u6210\u5458\uff08\u5373\u5176\u4e2d\u7684\u4e00\u4e2a\u5143\u7d20\uff09\uff0c\u4f46\u5bf9\u5b57\u7b26\u4e32\u6765\u8bf4\uff0c\u53ea\u6709\u5b83\u5305\u542b\u7684\u5b57\u7b26\u624d\u662f\u5176\u6210\u5458\u6216\u5143\u7d20\u3002\nin\u8fd0\u7b97\u7b26\u7684\u8fd4\u56de\u503c\u662f\u5e03\u5c14\u503c\u2018Ture'\u6216\u2018False''')\nof.close()\ntempstr = 'PiZiShu'\ntempchar = input('\u8bf7\u968f\u610f\u8f93\u5165\u4e00\u4e2a\u5b57\u6bcd\uff0c\u5e76\u6309\u786e\u8ba4\u952e\uff1a ') \nif tempchar in tempstr:print('Ture')\nelse :print('False')<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u957f\u5b57\u7b26\u4e32\u7684\u5904\u7406\u53caif\u6761\u4ef6<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[12,25,26,33,53,63,68],"class_list":{"0":"post-171","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-tech","7":"tag-abs","8":"tag-if","9":"tag-len","10":"tag-python","11":"tag-53","12":"tag-63","13":"tag-68","14":"h-entry","16":"h-as-article"},"_links":{"self":[{"href":"https:\/\/www.stusc.com\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stusc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stusc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stusc.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stusc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":0,"href":"https:\/\/www.stusc.com\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.stusc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stusc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stusc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}