{"id":517,"date":"2019-07-04T23:24:00","date_gmt":"2019-07-04T15:24:00","guid":{"rendered":"http:\/\/note.systw.net\/note\/?p=517"},"modified":"2023-11-03T23:26:06","modified_gmt":"2023-11-03T15:26:06","slug":"python-string","status":"publish","type":"post","link":"https:\/\/systw.net\/note\/archives\/517","title":{"rendered":"Python string"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u5b57\u4e32\u76f8\u52a0<\/strong><br>print strvar1 + strvar2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5b57\u4e32\u8f49\u6574\u6578<\/strong><br>int( var )<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5b57\u4e32\u8f49\u6d6e\u9ede\u6578<\/strong><br>float( var )<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6578\u5b57\u8f49\u6210\u5b57\u4e32<\/strong><br>str( var )<br>ex:<br>money=1200<br>print type(money)<br>money=str(money)<br>print type(money)<br>\u7d50\u679c\u5982\u4e0b<br>&lt; type &#8216;int&#8217;&gt;<br>&lt; type &#8216;str&#8217;&gt;<br>ex:<br>money=1200<br>if type(money)==int:<br>\u3000print \u2018int&#8217;<br>ps:<br>\u8b8a\u6578\u540d\u7a31\u82e5\u7528str\u6703\u767c\u73fe\u932f\u8aa4, \u5982\u4e0b\u6240\u793a<br>&gt;&gt;&gt; str=100<br>&gt;&gt;&gt; str(10)<br>Traceback (most recent call last):<br>File &#8220;&#8221;, line 1, in -toplevel-<br>str(10)<br>TypeError: &#8216;int&#8217; object is not callable<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u53bb\u9664\u7a7a\u767d<\/strong><br>.strip()<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5b57\u4e32\u622a\u53d6<\/strong><br>str[range]<br>ex:<br>str = &#8216;12345678&#8217;<br>print str[0:1] &gt;&gt; 1 # \u8f38\u51fastr\u4f4d\u7f6e0\u958b\u59cb\u5230\u4f4d\u7f6e1\u4ee5\u524d\u7684\u5b57\u5143<br>print str[1:6] &gt;&gt; 23456 # \u8f38\u51fastr\u4f4d\u7f6e1\u958b\u59cb\u5230\u4f4d\u7f6e6\u4ee5\u524d\u7684\u5b57\u5143<br>print str[1:] &gt;&gt; 2345678 # \u8f38\u51fastr\u4f4d\u7f6e1\u958b\u59cb\u5230\u6700\u5f8c\u7684\u5b57\u5143<br>print str[-5:] &gt;&gt; 45678 # \u8f38\u51fa\u5b57\u4e32\u53f35\u4f4d<br>print str[-1] &gt;&gt; 8 # \u8f38\u51fa\u5b57\u4e32\u53f31\u4f4d,\u5c31\u662f\u8f38\u51fa\u6700\u5f8c\u4e00\u500b\u5b57\u5143<br>print str[:-1] &gt;&gt; 1234567 # \u522a\u9664\u6700\u5f8c\u4e00\u500b\u5b57\u5143<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u66ff\u63db\u5b57\u4e32<\/strong><br>\u8b8a\u6578.replace(&#8220;\u66ff\u63db\u524d\u5b57\u4e32&#8221;\uff0c&#8221;\u66ff\u63db\u5f8c\u5b57\u4e32&#8221;[,\u6b21\u6578])<br>\u6b21\u6578:\u7559\u7a7a\uff0c\u8868\u793a\u66ff\u63db\u6240\u6709&nbsp;<br>ex:<br>str = &#8216;akakak&#8217;<br>str = str.replace(&#8216;k&#8217;,&#8217; 8&#8242;) # \u5c07\u5b57\u4e32\u88e1\u7684k\u5168\u90e8\u66ff\u63db\u70ba8<br>print str &gt;&gt; &#8216;a8a8a8&#8217; # \u8f38\u51fa\u7d50\u679c<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u627e\u5b57\u4e32<\/strong><br>\u8b8a\u6578.find(&#8220;\u8981\u67e5\u627e\u7684\u5167\u5bb9&#8221;[,\u958b\u59cb\u4f4d\u7f6e,\u7d50\u675f\u4f4d\u7f6e])<br>\u958b\u59cb\u4f4d\u7f6e\u548c\u7d50\u675f\u4f4d\u7f6e:\u8868\u793a\u8981\u67e5\u627e\u7684\u7bc4\u570d\uff0c\u7a7a\u8868\u793a\u627e\u6240\u6709\u5b57\u4e32\uff0c\u67e5\u5230\u5f8c\u6703\u50b3\u56de\u4f4d\u7f6e\uff0c\u4f4d\u7f6e\u5f9e0\u958b\u59cb\u7b97\uff0c\u5982\u679c\u6c92\u627e\u5230\u5247\u50b3\u56de-1<br>ex:<br>str = &#8216;a,hello&#8217;<br>print str.find(&#8216;hello&#8217;) # \u5728\u5b57\u4e32str\u88e1\u67e5\u627e\u5b57\u4e32<br>\u7d50\u679c\u5982\u4e0b<br>2<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5b57\u5143\u5206\u5272<\/strong><br>\u8b8a\u6578.split(&#8220;\u5206\u5272\u6a19\u793a\u7b26\u865f&#8221;,[count])<br>count: \u8868\u793a\u5206\u5272\u6700\u5927\u6b21\u6578\uff0c\u7559\u7a7a\u8868\u793a\u5206\u5272\u6240\u6709<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ex:<br>str = 'a,b,c,d'<br>strlist = str.split(',')<br>\u3000for value in strlist:<br>\u3000\u3000print value<br>ex:<br>str='tom n ray n john n'<br>strlist = str.strip().split(\"n\")<br>\u3000for value in strlist:<br>\u3000\u3000print value<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><br><strong>list\u5b57\u4e32\u5408\u4f75<\/strong><br>.join( &lt; list &gt; )<br>ex:<br>listdata = [&#8216;my&#8217;,&#8217;name&#8217;,&#8217;is&#8217;,&#8217;bob&#8217;]<br>col=&#8217; &#8216;<br>col.join(listdata)<br>print col<br>\u7d50\u679c\u5982\u4e0b<br>&#8216;my name is bob&#8217;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b57\u4e32\u76f8\u52a0print strvar1 + strvar2 \u5b57\u4e32 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"","fifu_image_alt":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[14],"tags":[],"class_list":["post-517","post","type-post","status-publish","format-standard","hentry","category-develop"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":531,"url":"https:\/\/systw.net\/note\/archives\/531","url_meta":{"origin":517,"position":0},"title":"C\u8a9e\u8a00\u6458\u8981","author":"raymond","date":"2017 \u5e74 12 \u6708 10 \u65e5","format":false,"excerpt":"C\u7684\u7a0b\u5f0f\u7d50\u69cb #include\u00a0\/\/\u524d\u7f6e\u8655\u7406\u5668\u6307\u4ee4void main(void){\u3000\/\/main\u8868\u793a\u2026","rel":"","context":"\u5728\u300c\u958b\u767c\u300d\u4e2d","block_context":{"text":"\u958b\u767c","link":"https:\/\/systw.net\/note\/archives\/category\/develop"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":145,"url":"https:\/\/systw.net\/note\/archives\/145","url_meta":{"origin":517,"position":1},"title":"XSS","author":"raymond","date":"2020 \u5e74 8 \u6708 7 \u65e5","format":false,"excerpt":"XSS(cross-site scripting)\uff1aattacker uses a web appl\u2026","rel":"","context":"\u5728\u300cClientSide\u300d\u4e2d","block_context":{"text":"ClientSide","link":"https:\/\/systw.net\/note\/archives\/category\/hackerthreat\/clientside"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":17,"url":"https:\/\/systw.net\/note\/archives\/17","url_meta":{"origin":517,"position":2},"title":"burpsuite intruder","author":"raymond","date":"2023 \u5e74 10 \u6708 15 \u65e5","format":false,"excerpt":"position \u5728attack type\u67094\u7a2e\u53ef\u9078\uff0c\u8aaa\u660e\u5982\u4e0b Sniper \u53ef\u91dd\u5c0d\u8acb\u6c42\u4e2d\u7684\u4e00\u500b\u4f4d\u7f6e\u2026","rel":"","context":"\u5728\u300cred team\u300d\u4e2d","block_context":{"text":"red team","link":"https:\/\/systw.net\/note\/archives\/category\/securitytool\/red-team"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1038,"url":"https:\/\/systw.net\/note\/archives\/1038","url_meta":{"origin":517,"position":3},"title":"HTB Neonify","author":"raymond","date":"2023 \u5e74 12 \u6708 3 \u65e5","format":false,"excerpt":"\u653b\u64ca\u7b56\u7565\u70ba\u9952\u904e\u5b57\u4e32\u4fdd\u8b77,\u4e26\u900f\u904eruby ssti\u57f7\u884c\u4efb\u610f\u6307\u4ee4","rel":"","context":"\u5728\u300c\u653b\u64ca\u624b\u6cd5\u300d\u4e2d","block_context":{"text":"\u653b\u64ca\u624b\u6cd5","link":"https:\/\/systw.net\/note\/archives\/category\/hackerskill"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":523,"url":"https:\/\/systw.net\/note\/archives\/523","url_meta":{"origin":517,"position":4},"title":"Python Array","author":"raymond","date":"2014 \u5e74 11 \u6708 23 \u65e5","format":false,"excerpt":"python \u8655\u7406array\u4e3b\u8981\u6709\u4ee5\u4e0b\u4e09\u7a2e\u65b9\u5f0flist ,dict , tuple ........\u2026","rel":"","context":"\u5728\u300c\u958b\u767c\u300d\u4e2d","block_context":{"text":"\u958b\u767c","link":"https:\/\/systw.net\/note\/archives\/category\/develop"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1047,"url":"https:\/\/systw.net\/note\/archives\/1047","url_meta":{"origin":517,"position":5},"title":"HTB COP","author":"raymond","date":"2023 \u5e74 12 \u6708 20 \u65e5","format":false,"excerpt":"\u4f7f\u7528sql injection\u6f0f\u6d1e\u5c07\u60e1\u610f\u7684\u53cd\u5e8f\u5217\u5316\u5167\u5bb9\u5582\u5165\u76ee\u6a19,\u4ee5\u57f7\u884c\u7279\u5b9a\u7684\u60e1\u610f\u6307\u4ee4","rel":"","context":"\u5728\u300c\u653b\u64ca\u624b\u6cd5\u300d\u4e2d","block_context":{"text":"\u653b\u64ca\u624b\u6cd5","link":"https:\/\/systw.net\/note\/archives\/category\/hackerskill"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/comments?post=517"}],"version-history":[{"count":0,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/posts\/517\/revisions"}],"wp:attachment":[{"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/media?parent=517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/categories?post=517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/systw.net\/note\/wp-json\/wp\/v2\/tags?post=517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}