{"id":205396,"date":"2025-05-29T13:29:57","date_gmt":"2025-05-29T05:29:57","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205396\/"},"modified":"2025-05-29T13:29:57","modified_gmt":"2025-05-29T05:29:57","slug":"python-day-%e5%ad%97%e7%ac%a6%e4%b8%b2%e5%87%bd%e6%95%b0%e3%80%81%e5%be%aa%e7%8e%af%e3%80%81ifelse-%e6%9d%a1%e4%bb%b6%e5%92%8c%e4%bb%bb%e5%8a%a1","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205396\/","title":{"rendered":"Python Day \u5b57\u7b26\u4e32\u51fd\u6570\u3001\u5faa\u73af\u3001ifelse \u6761\u4ef6\u548c\u4efb\u52a1"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python Day \u5b57\u7b26\u4e32\u51fd\u6570\u3001\u5faa\u73af\u3001ifelse \u6761\u4ef6\u548c\u4efb\u52a1<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPython Day \u5b57\u7b26\u4e32\u51fd\u6570\u3001\u5faa\u73af\u3001ifelse \u6761\u4ef6\u548c\u4efb\u52a1\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><strong>\u67e5\u627e():<\/strong><br \/> \u5728\u5b57\u7b26\u4e32\u4e2d\u641c\u7d22\u6307\u5b9a\u503c\u5e76\u8fd4\u56de\u627e\u5230\u5b83\u7684\u4f4d\u7f6e\u3002<br \/> \u4f8b\u5982\uff1a<\/p>\n<pre>txt = \"hello, welcome to my world.\"\n\nx = txt.find(\"welcome\")\n\nprint(x)\n\n<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>7\n\n<\/pre>\n<p>\u56e0\u6b64 <strong>welcome<\/strong> \u6839\u636e\u7d22\u5f15\u4f4d\u4e8e\u7b2c\u4e03\u4f4d\u3002\u5982\u679c\u7ed9\u51fa\u4efb\u4f55\u5176\u4ed6\u672a\u5b9a\u4e49\u7684\u5355\u8bcd\uff0c\u5219\u7ed3\u679c\u5c06\u4e3a <strong>-1<\/strong>\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u5982\u679c\u4f7f\u7528\u7d22\u5f15\u51fd\u6570\u800c\u4e0d\u662ffind\uff0c\u90a3\u4e48\u5b83\u5c06\u663e\u793a\u201cvalueerror\uff1a\u5b50\u5b57\u7b26\u4e32\u672a\u627e\u5230\u201d\u3002\u5982\u679c\u5b9a\u4e49\uff0c\u5219\u8f93\u51fa\u5c06\u4e0efind\u51fd\u6570\u76f8\u540c\u3002<\/strong><\/p>\n<p><strong>\u5faa\u73af\uff1a<\/strong><br \/> for\u5faa\u73af\uff1a<br \/> \u4f8b\u5982\uff1a1<\/p>\n<pre>txt = '1234'\n\nfor num in txt:\n    print(num,end=' ')\n\n<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>1 2 3 4\n<\/pre>\n<p>\u4f8b\u5982\uff1a2<\/p>\n<pre>name = input(\"enter name: \")\nprint(name)\nfor alphabet in name:\n    print(alphabet, end='*') \n<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>enter name: guru\nguru\ng*u*r*u*\n<\/pre>\n<p><strong>\u5982\u679c\uff1a<\/strong><br \/> \u5b83\u6839\u636e\u8bed\u53e5\u7684\u771f\u5047\u6765\u51b3\u5b9a\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241130\/1732969113674b0299039ab.jpg\" class=\"aligncenter\"><br \/> \u4f8b\u5982\uff1a<\/p>\n<pre>txt = '12a4'\n\nfor num in txt:\n    if num&gt;='0' and num&lt;='9':\n        print(num,end=' ')\n    else:\n        print('not decimal',end=' ')\n\n<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>1 2 not decimal 4 \n<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c1,2,4 \u662f\u5341\u8fdb\u5236\uff0c\u4f46 a \u4e0d\u662f\u5c0f\u6570\uff0c\u56e0\u6b64\u5728\u8f93\u51fa\u4e2d\uff0c\u6839\u636e\u5176\u4ed6\u6761\u4ef6\uff0c\u5b83\u663e\u793a\u7684\u4e0d\u662f\u5341\u8fdb\u5236\u3002<\/p>\n<p><strong>\u4efb\u52a1\uff1a<\/strong><\/p>\n<p>\u62c9\u514b\u5e0c\u7c73\u00b7\u666e\u91cc\u5854<br \/> \u5927\u5e08 prasanna<br \/> \u53e4\u6c49\u62c9\u8d3e<br \/> \u74e6\u62c9\u5854\u62c9\u626c<\/p>\n<p>\u67e5\u627e\uff1a<br \/> 1: \u4ee5\u5b57\u6bcd\u201cg\u201d\u5f00\u5934\u7684\u540d\u5b57<br \/> 2\uff1a\u540d\u79f0\u4ee5\u201ca\u201d\u7ed3\u5c3e<br \/> 3\uff1a\u540d\u79f0\u4e4b\u95f4\u6709\u7a7a\u683c<br \/> 4\uff1a\u540d\u5b57\u8d85\u8fc79\u4e2a\u5b57\u6bcd<\/p>\n<pre>name=input(\"enter names: \")\nnames=(name).split(\",\")\n\nfor letter in names:\n    if letter.startswith('g'):\n        print(\"names starts with g are: \",letter)\n    else :\n        letter.endswith('a')\n        print(\"names end with a are: \",letter)\nfor space in names:\n    for word in space:\n        if word==' ':\n            print(\"names with space: \",space)\n        else:\n            continue\nfor character in names:\n    if len(character)&gt;9:\n        print(\"names with more than 9 letters: \",character)\n<\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Enter names: guru prasanna,guhanraja,lakshmi pritha,varatharajan\nNames starts with g are:  guru prasanna\nNames starts with g are:  guhanraja\nNames end with a are:  lakshmi pritha\nNames end with a are:  varatharajan\nNames with space:  guru prasanna\nNames with space:  lakshmi pritha\nNames with more than 9 letters:  guru prasanna\nNames with more than 9 letters:  lakshmi pritha\nNames with more than 9 letters:  varatharajan\n\n\n<\/pre>\n<p>\u597d\u4e86\uff0c\u672c\u6587\u5230\u6b64\u7ed3\u675f\uff0c\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u300aPython Day \u5b57\u7b26\u4e32\u51fd\u6570\u3001\u5faa\u73af\u3001ifelse \u6761\u4ef6\u548c\u4efb\u52a1\u300b\uff0c\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u7ed9\u5927\u5bb6\u5206\u4eab\u66f4\u591a\u6587\u7ae0\u77e5\u8bc6\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python Day \u5b57\u7b26\u4e32\u51fd\u6570&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205396","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205396","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205396"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205396\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}