{"id":56002,"date":"2025-02-22T09:30:46","date_gmt":"2025-02-22T01:30:46","guid":{"rendered":"https:\/\/fwq.ai\/blog\/56002\/"},"modified":"2025-02-22T09:30:46","modified_gmt":"2025-02-22T01:30:46","slug":"%e4%bb%a3%e7%a0%81%e4%bc%98%e5%8c%96_it%e4%b8%93%e7%94%a8prompt-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/56002\/","title":{"rendered":"\u4ee3\u7801\u4f18\u5316_IT\u4e13\u7528Prompt"},"content":{"rendered":"<h1>\u591a\u8fdb\u7a0b\u5e76\u884c\u8fd0\u7b97\u81ea\u52a8\u8f6c\u6362<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u628a\u4e0b\u9762\u8fd9\u6bb5 Python \u4ee3\u7801\u8f6c\u6362\u4e3a\u591a\u8fdb\u7a0b\u5e76\u884c\u8fd0\u7b97 \u2014\u2014<\/p>\n<p> <\/p>\n<p>**Python \u4ee3\u7801<\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u628a\u4e0b\u9762\u8fd9\u6bb5 Python \u4ee3\u7801\u8f6c\u6362\u4e3a\u591a\u8fdb\u7a0b\u5e76\u884c\u8fd0\u7b97 \u2014\u2014<\/p>\n<p>import time<br \/> def calc_square(numbers):<br \/> for n in numbers:<br \/> print(f&#8217;\\n{n} ^ 2 = {n*n}&#8217;)<br \/> time.sleep(0.1)<\/p>\n<p>def calc_cube(numbers):<br \/> for n in numbers:<br \/> print(f&#8217;\\n{n} ^ 3 = {n<em>n<\/em>n}&#8217;)<br \/> time.sleep(0.1)<\/p>\n<p>numbers = [2, 3, 5, 8] start = time.time()<br \/> calc_square(numbers)<br \/> calc_cube(numbers)<br \/> end = time.time()<\/p>\n<p>print(&#8216;Execution Time: {}&#8217;.format(end-start))<\/p>\n<h1>\u4ee3\u7801\u6548\u7387\u5bf9\u6bd4<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u6d4b\u8bd5\u5de5\u7a0b\u5e08\uff0c\u6211\u60f3\u5bf9\u6bd4\u4ee5\u4e0b\u4e24\u6bb5\u6267\u884c\u76f8\u540c\u4efb\u52a1\u7684\u7b97\u6cd5\u4ee3\u7801\u7684\u8fd0\u884c\u6548\u7387\uff0c\u8bf7\u5199\u51fa\u4e00\u6bb5\u5faa\u73af\u6267\u884c\u4ee5\u4e0b\u7b97\u6cd5&nbsp;<strong>[ \u53c2\u6570 ]<\/strong>&nbsp;\u7684\u4ee3\u7801\uff0c\u5e76\u7ed9\u51fa\u4e24\u6bb5\u4ee3\u7801\u5404\u81ea\u7684\u6267\u884c\u65f6\u95f4\u4ee5\u53ca\u76f8\u5173\u7684\u7edf\u8ba1\u4fe1\u606f<\/p>\n<p><strong>\u4ee3\u7801 1:<\/strong><\/p>\n<p><strong>\u4ee3\u7801 2:<\/strong><\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u6d4b\u8bd5\u5de5\u7a0b\u5e08\uff0c\u6211\u60f3\u5bf9\u6bd4\u4ee5\u4e0b\u4e24\u6bb5\u6267\u884c\u76f8\u540c\u4efb\u52a1\u7684\u7b97\u6cd5\u4ee3\u7801\u7684\u8fd0\u884c\u6548\u7387\uff0c\u8bf7\u5199\u51fa\u4e00\u6bb5\u5faa\u73af\u6267\u884c\u4ee5\u4e0b\u7b97\u6cd5&nbsp;<strong>[ 10\u6b21 ]<\/strong>&nbsp;\u7684\u4ee3\u7801\uff0c\u5e76\u7ed9\u51fa\u4e24\u6bb5\u4ee3\u7801\u5404\u81ea&gt;\u7684\u6267\u884c\u65f6\u95f4\u4ee5\u53ca\u76f8\u5173\u7684\u7edf\u8ba1\u4fe1\u606f<\/p>\n<pre><code># \u4ee3\u78011:\ndef compute1(a, b):\n    return (a+b) \/ (a*b)\n\n# \u4ee3\u78012:\nimport numpy as np\ndef compute2(a, b):\n    return np.divide(np.sum([a,b]), np.multiply(a,b))\n\n<\/code><\/pre>\n<h1>\u81ea\u52a8\u5355\u5143\u5316\u6d4b\u8bd5<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u6d4b\u8bd5\u5de5\u7a0b\u5e08\uff0c\u8bf7\u7f16\u5199&nbsp;<strong>[ \u51fd\u6570 ]<\/strong>&nbsp;\u7684\u5355\u5143\u6d4b\u8bd5\u4ee3\u7801\uff0c\u6d4b\u8bd5\u6761\u4ef6\u4e3a\uff1a<\/p>\n<p><strong>\u6d4b\u8bd5\u6761\u4ef6<\/strong><\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u6d4b\u8bd5\u5de5\u7a0b\u5e08\uff0c\u8bf7\u7f16\u5199&nbsp;<strong>[ def compute(a, b) ]<\/strong>&nbsp;\u7684\u5355\u5143\u6d4b\u8bd5\u4ee3\u7801\uff0c\u6d4b\u8bd5\u6761\u4ef6\u4e3a\uff1a<\/p>\n<pre><code>\u8f93\u5165\uff1a1\u30011.2\u30010.99 | \u8f93\u51fa\uff1a1\u30011.2\u30010.99\n\u8f93\u5165\uff1a-1\u3001-1.2\u3001-0.99 | \u8f93\u51fa\uff1a1\u30011.2\u30010.99\n\u8f93\u5165\uff1a0 | \u8f93\u51fa\uff1a0\n\u8f93\u5165\uff1aNone\u3001[]\u3001{} | \u8f93\u51fa\uff1aTypeError\n<\/code><\/pre>\n<h1>\u4ee3\u7801\u52a0\u901f<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u5de5\u7a0b\u5e08\uff0c\u5e2e\u6211\u4f18\u5316\u4ee5\u4e0b\u4ee3\u7801\u7684\u6267\u884c\u6548\u7387 \u2014\u2014<\/p>\n<p><strong>Python \u4ee3\u7801<\/strong><\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u5de5\u7a0b\u5e08\uff0c\u5e2e\u6211\u4f18\u5316\u4ee5\u4e0b\u4ee3\u7801\u7684\u6267\u884c\u6548\u7387 \u2014\u2014<\/p>\n<p>def test(y):<br \/> sum = 0<br \/> for i in range (y+1):<br \/> sum += 1<br \/> return sum<\/p>\n<h1>Pandas \u4ee3\u7801\u4f18\u5316<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u4ee3\u7801\u4f18\u5316\u5668\uff0c\u5e2e\u6211\u4f18\u5316\u4ee5\u4e0b Pandas \u4ee3\u7801 \u2014\u2014<\/p>\n<p><strong>Python \u4ee3\u7801<\/strong><\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u4ee3\u7801\u4f18\u5316\u5668\uff0c\u5e2e\u6211\u4f18\u5316\u4ee5\u4e0b Pandas \u4ee3\u7801 \u2014\u2014<\/p>\n<p>import pandas as pd<\/p>\n<p>df = pd.read_csv(data_path + &#8220;titles.csv&#8221;)<br \/> df_bad = df.query(&#8220;runtime &gt; 30 &amp; type == &#8216;SHOW'&#8221;)<br \/> df_bad [&#8220;score&#8221;] = df_bad&#8221;imdb_score&#8221;, &#8220;tmdb_score&#8221;.sum(axis=1)<br \/> df_bad = df_bad&#8221;seasons&#8221;, &#8220;score&#8221;<br \/> df_bad = df_bad.groupby(&#8220;seasons&#8221;).agg([&#8220;count&#8221;, &#8220;mean&#8221;])<br \/> df_bad = df_bad.droplevel(axis=1, level=0)<br \/> df_bad = df_bad.query(&#8220;count &gt; 10&#8221;)<\/p>\n<p>df_bad.head()<\/p>\n<h1>\u4f4e\u7ea7\u4ee3\u7801\u6539\u5199<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u4ee3\u7801\u4f18\u5316\u5668\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5199\u7684\u6bd4\u8f83\u4f4e\u7ea7\uff0c\u8bf7\u5e2e\u6211\u4fee\u6539 \u2014\u2014<\/p>\n<p><strong>Python \u4ee3\u7801<\/strong><\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u4ee3\u7801\u4f18\u5316\u5668\uff0c\u4e0b\u9762\u7684\u4ee3\u7801\u5199\u7684\u6bd4\u8f83\u4f4e\u7ea7\uff0c\u8bf7\u5e2e\u6211\u4fee\u6539 \u2014\u2014<\/p>\n<p>numbers = [1, 2, 3] letters =[&#8220;A&#8221;, &#8220;B&#8221;, &#8220;C&#8221;] <\/p>\n<p>for index in range (len(numbers)):<br \/> print(numbers[index], letters[index])<\/p>\n<h1>\u4ee3\u7801\u7b80\u5316<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u4ee3\u7801\u4f18\u5316\u5668\uff0c\u7b80\u5316\u4e0b\u9762\u7684\u4ee3\u7801 \u2014\u2014<\/p>\n<p><strong>Python \u4ee3\u7801<\/strong><\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u4ee3\u7801\u4f18\u5316\u5668\uff0c\u7b80\u5316\u4e0b\u9762\u7684\u4ee3\u7801 \u2014\u2014<\/p>\n<p>classes = [&#8216;Intro to Python&#8217;,<br \/> &#8216;R Data Analysis&#8217;,<br \/> &#8216;Python Machine Learning&#8217;] grades = [98,<br \/> 96,<br \/> 89] grade_dict = {}<br \/> for idx in range(len(classes)):<br \/> grade_dict[classes[idx]] = grades[idx] print(grade_dict)<\/p>\n<h1>\u4ee3\u7801\u6392\u9519<\/h1>\n<h3>\u6307\u4ee4\u683c\u5f0f<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u5de5\u7a0b\u5e08\uff0c\u5e2e\u6211\u6392\u9664\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u7684\u9519\u8bef \u2014\u2014<\/p>\n<p><strong>Python \u4ee3\u7801<\/strong><\/p>\n<h3>\u6307\u4ee4\u793a\u4f8b<\/h3>\n<p>\u8bf7\u4f5c\u4e3a\u4e00\u4e2a\u8f6f\u4ef6\u5de5\u7a0b\u5e08\uff0c\u5e2e\u6211\u6392\u9664\u4ee5\u4e0b\u4ee3\u7801\u4e2d\u7684\u9519\u8bef \u2014\u2014<\/p>\n<p>def add_from_1_to_k(k):<br \/> if (k &gt; 0):<br \/> result = k + add_from_1_to_k(k &#8211; 1)<br \/> return result<\/p>\n<p>add_from_1_to_k(-10)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u591a\u8fdb\u7a0b\u5e76\u884c\u8fd0\u7b97\u81ea\u52a8\u8f6c\u6362 \u6307\u4ee4\u683c\u5f0f \u8bf7\u628a\u4e0b\u9762\u8fd9\u6bb5 Python \u4ee3\u7801\u8f6c\u6362\u4e3a\u591a\u8fdb\u7a0b\u5e76\u884c\u8fd0\u7b97 \u2014\u2014 **Python \u4ee3\u7801 \u6307\u4ee4\u793a\u4f8b \u8bf7\u628a\u4e0b\u9762\u8fd9\u6bb5 Python \u4ee3\u7801\u8f6c\u6362\u4e3a\u591a\u8fdb\u7a0b\u5e76\u884c\u8fd0\u7b97 \u2014\u2014 import time def calc_square(numbers): for n in numbers: print(f&#8217;\\n{n} ^ 2 = {n*n}&#8217;) time.sleep(0.1) def calc_cube(numbers): for n in numbers: print(f&#8217;\\n{n} ^ 3 = {nnn}&#8217;) time.sleep(0.1) numbers = [2, 3, 5, 8] start = time.time() calc_square(numbers) calc_cube(numbers) end = time.time() print(&#8216;Execution Time: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-56002","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/56002","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=56002"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/56002\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=56002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=56002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=56002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}