{"id":184177,"date":"2022-04-08T21:32:43","date_gmt":"2022-04-08T13:32:43","guid":{"rendered":"http:\/\/www.idc.net\/help\/184177\/"},"modified":"2022-04-08T21:32:43","modified_gmt":"2022-04-08T13:32:43","slug":"python-%e7%a8%8b%e5%ba%8f%ef%bc%9a%e5%8e%bb%e9%99%a4%e5%ad%97%e7%ac%a6%e4%b8%b2%e4%b8%ad%e6%a0%87%e7%82%b9%e7%ac%a6%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/184177\/","title":{"rendered":"Python \u7a0b\u5e8f\uff1a\u53bb\u9664\u5b57\u7b26\u4e32\u4e2d\u6807\u70b9\u7b26\u53f7"},"content":{"rendered":"<p>\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1a<\/p>\n<p>\u7f16\u5199\u4e00\u4e2a Python \u7a0b\u5e8f\u6765\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6807\u70b9\u7b26\u53f7\u3002\u6211\u4eec\u58f0\u660e\u4e86\u4e00\u4e2a\u53ef\u80fd\u7684\u6807\u70b9\u7b26\u53f7\u5b57\u7b26\u4e32\uff0c\u5e76\u4f7f\u7528 for \u5faa\u73af\u6765\u8fed\u4ee3\u7ed9\u5b9a\u7684\u5b57\u7b26\u4e32\u3002\u5728\u8fd9\u4e2a python \u793a\u4f8b\u4e2d\uff0cif \u8bed\u53e5\u68c0\u67e5\u6bcf\u4e2a\u5b57\u7b26\u662f\u5426\u6709\u6807\u70b9\u7b26\u53f7\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230\uff0cchar \u5c06\u5206\u914d\u7ed9\u4e00\u4e2a\u65b0\u7684\u5b57\u7b26\u4e32\uff0c\u8fd9\u4f1a\u5220\u9664\u6807\u70b9\u7b26\u53f7\u3002<\/p>\n<pre><code># Python Program to Remove Punctuations in a String\n\npunctuations = '''`[email&nbsp;protected]#$%^&amp;*()-_=+{}[]\\|;:'\",.&lt;&gt;?'''\n\norgStr = \"Hi!!, Welcome, Tutorial-Gateway?\"\n\nnewStr = \"\"\n\nfor char in orgStr:\n    if char not in punctuations:\n        newStr = newStr + char\n\nprint(\"\\nThe Original String Before Removing Punctuations\")\nprint(orgStr)\n\nprint(\"\\nThe Final String After Removing Punctuations\")\nprint(newStr)<\/code><\/pre>\n<\/p>\n<p>\u8fd9\u4e2a Python \u7a0b\u5e8f\u5141\u8bb8\u7528\u6237\u8f93\u5165\u4e00\u4e2a\u5b57\u7b26\u4e32\u5e76\u5220\u9664\u5176\u4e2d\u7684\u6807\u70b9\u7b26\u53f7\u3002<\/p>\n<pre><code>orgStr = input(\"Please Enter Any String = \")\n\npunctuations = '''`[email&nbsp;protected]#$%^&amp;*()-_=+{}[]\\|;:'\",.&lt;&gt;?'''\n\nnewStr = \"\"\n\nfor char in orgStr:\n    if char not in punctuations:\n        newStr = newStr + char\n\nprint(\"\\nThe Original String Before Removing Punctuations\")\nprint(orgStr)\n\nprint(\"\\nThe Final String After Removing Punctuations\")\nprint(newStr)<\/code><\/pre>\n<pre><code>Please Enter Any String = [[email&nbsp;protected]](\/cdn-cgi\/l\/email-protection)#&amp;^%$# Python&lt;&gt;? Programs?\n\nThe Original String Before Removing Punctuations\n[[email&nbsp;protected]](\/cdn-cgi\/l\/email-protection)#&amp;^%$# Python&lt;&gt;? Programs?\n\nThe Final String After Removing Punctuations\nLearn Python Programs<\/code><\/pre>\n<p>Python \u7a0b\u5e8f\u4f7f\u7528 while \u5faa\u73af\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6807\u70b9\u7b26\u53f7\u3002<\/p>\n<pre><code>orgStr = input(\"Please Enter Any String = \")\n\npunctuations = '''`[email&nbsp;protected]#$%^&amp;*()-_=+{}[]\\|;:'\",.&lt;&gt;?'''\n\nnewStr = \"\"\n\ni = 0\nwhile i &lt; len(orgStr):\n    if orgStr[i] not in punctuations:\n        newStr = newStr + orgStr[i]\n    i = i + 1\n\nprint(\"\\nThe Original String Before Removing Punctuations\")\nprint(orgStr)\n\nprint(\"\\nThe Final String After Removing Punctuations\")\nprint(newStr)<\/code><\/pre>\n<pre><code>Please Enter Any String = [[email&nbsp;protected]](\/cdn-cgi\/l\/email-protection) tutorial @@#&amp;^ gateway {}\\ followers\n\nThe Original String Before Removing Punctuations\n[[email&nbsp;protected]](\/cdn-cgi\/l\/email-protection) tutorial @@#&amp;^ gateway {}\\ followers\n\nThe Final String After Removing Punctuations\nhi tutorial  gateway  followers<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1a \u7f16\u5199\u4e00\u4e2a Python \u7a0b\u5e8f\u6765\u5220\u9664\u5b57\u7b26\u4e32\u4e2d\u7684\u6807\u70b9\u7b26\u53f7\u3002\u6211\u4eec\u58f0\u660e\u4e86\u4e00\u4e2a\u53ef\u80fd\u7684\u6807\u70b9\u7b26\u53f7\u5b57 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-184177","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184177","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=184177"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/184177\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=184177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=184177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=184177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}