{"id":987177,"date":"2024-12-27T07:51:17","date_gmt":"2024-12-26T23:51:17","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/987177.html"},"modified":"2024-12-27T07:51:19","modified_gmt":"2024-12-26T23:51:19","slug":"python%e5%a6%82%e4%bd%95%e8%be%93%e5%85%a5%e5%ad%98%e5%85%a5%e5%ad%97%e5%85%b8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/987177.html","title":{"rendered":"python\u5982\u4f55\u8f93\u5165\u5b58\u5165\u5b57\u5178"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25063419\/950ca1b0-b49d-4d5a-b6c5-94b2d7ce9791.webp\" alt=\"python\u5982\u4f55\u8f93\u5165\u5b58\u5165\u5b57\u5178\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5c06\u8f93\u5165\u7684\u6570\u636e\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528input()\u51fd\u6570\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u4f7f\u7528\u5b57\u5178\u7684\u8d4b\u503c\u8bed\u6cd5\u5c06\u8f93\u5165\u7684\u6570\u636e\u5b58\u50a8\u4e3a\u5b57\u5178\u7684\u952e\u548c\u503c\u3002\u5b9e\u73b0\u65b9\u6cd5\u5305\u62ec\uff1a\u76f4\u63a5\u8d4b\u503c\u3001\u4f7f\u7528\u5faa\u73af\u6279\u91cf\u8f93\u5165\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f\u7b49\u3002<\/strong> \u5176\u4e2d\uff0c\u76f4\u63a5\u8d4b\u503c\u662f\u6700\u57fa\u7840\u7684\u65b9\u6cd5\uff0c\u9002\u7528\u4e8e\u5c11\u91cf\u6570\u636e\u7684\u5b58\u50a8\u3002<\/p>\n<\/p>\n<p><p>\u76f4\u63a5\u8d4b\u503c\u7684\u65b9\u6cd5\uff1a\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u7a7a\u5b57\u5178\uff0c\u7136\u540e\u6839\u636e\u9700\u8981\u4f7f\u7528input()\u51fd\u6570\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5982\u679c\u9700\u8981\u5b58\u50a8\u4e00\u4e2a\u4eba\u7684\u59d3\u540d\u548c\u5e74\u9f84\uff0c\u53ef\u4ee5\u8fd9\u6837\u5b9e\u73b0\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">person_info = {}<\/p>\n<p>name = input(&quot;\u8bf7\u8f93\u5165\u59d3\u540d: &quot;)<\/p>\n<p>age = input(&quot;\u8bf7\u8f93\u5165\u5e74\u9f84: &quot;)<\/p>\n<p>person_info[&#39;name&#39;] = name<\/p>\n<p>person_info[&#39;age&#39;] = age<\/p>\n<p>print(person_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\u76f4\u63a5\uff0c\u9002\u5408\u4e8e\u5904\u7406\u5c11\u91cf\u6570\u636e\u7684\u573a\u666f\u3002\u4f46\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\uff0c\u6b64\u65f6\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5faa\u73af\u6216\u8005\u5b57\u5178\u63a8\u5bfc\u5f0f\u6765\u4f18\u5316\u6570\u636e\u5b58\u50a8\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5728Python\u4e2d\u5982\u4f55\u901a\u8fc7\u4e0d\u540c\u7684\u65b9\u6cd5\u5c06\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u76f4\u63a5\u8d4b\u503c<\/h3>\n<\/p>\n<p><p>\u76f4\u63a5\u8d4b\u503c\u662f\u5c06\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u76f4\u63a5\u8d4b\u4e88\u5b57\u5178\u7684\u67d0\u4e2a\u952e\u503c\u5bf9\u7684\u65b9\u6cd5\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u4e8e\u5c11\u91cf\u6570\u636e\u7684\u5b58\u50a8\uff0c\u6613\u4e8e\u7406\u89e3\u548c\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u5b57\u5178\u5e76\u5b58\u50a8\u5355\u4e2a\u8f93\u5165<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b57\u5178\u7684\u952e\u6765\u5b58\u50a8\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5c06\u7528\u6237\u7684\u59d3\u540d\u548c\u5e74\u9f84\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">person_info = {}<\/p>\n<p>name = input(&quot;\u8bf7\u8f93\u5165\u59d3\u540d: &quot;)<\/p>\n<p>age = input(&quot;\u8bf7\u8f93\u5165\u5e74\u9f84: &quot;)<\/p>\n<p>person_info[&#39;name&#39;] = name<\/p>\n<p>person_info[&#39;age&#39;] = age<\/p>\n<p>print(person_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e00\u4e2a\u7a7a\u5b57\u5178<code>person_info<\/code>\uff0c\u7136\u540e\u901a\u8fc7<code>input()<\/code>\u51fd\u6570\u83b7\u53d6\u7528\u6237\u7684\u59d3\u540d\u548c\u5e74\u9f84\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002\u6700\u540e\uff0c\u901a\u8fc7<code>print()<\/code>\u51fd\u6570\u8f93\u51fa\u5b57\u5178\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h4>2. \u5b58\u50a8\u591a\u4e2a\u8f93\u5165<\/h4>\n<\/p>\n<p><p>\u5f53\u9700\u8981\u5b58\u50a8\u591a\u4e2a\u8f93\u5165\u65f6\uff0c\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u5e76\u5c06\u6bcf\u4e2a\u8f93\u5165\u5b58\u50a8\u5230\u5b57\u5178\u7684\u4e0d\u540c\u952e\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">student_scores = {}<\/p>\n<p>student_scores[&#39;math&#39;] = input(&quot;\u8bf7\u8f93\u5165\u6570\u5b66\u6210\u7ee9: &quot;)<\/p>\n<p>student_scores[&#39;english&#39;] = input(&quot;\u8bf7\u8f93\u5165\u82f1\u8bed\u6210\u7ee9: &quot;)<\/p>\n<p>student_scores[&#39;science&#39;] = input(&quot;\u8bf7\u8f93\u5165\u79d1\u5b66\u6210\u7ee9: &quot;)<\/p>\n<p>print(student_scores)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5b57\u5178<code>student_scores<\/code>\uff0c\u5e76\u5c06\u7528\u6237\u8f93\u5165\u7684\u6570\u5b66\u3001\u82f1\u8bed\u548c\u79d1\u5b66\u6210\u7ee9\u5206\u522b\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u5bf9\u5e94\u7684\u952e\u4e0a\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5faa\u73af\u6279\u91cf\u8f93\u5165<\/h3>\n<\/p>\n<p><p>\u5f53\u9700\u8981\u5b58\u50a8\u5927\u91cf\u6570\u636e\u65f6\uff0c\u76f4\u63a5\u8d4b\u503c\u7684\u65b9\u6cd5\u53ef\u80fd\u4f1a\u663e\u5f97\u5197\u957f\u4e14\u91cd\u590d\u3002\u6b64\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u6765\u7b80\u5316\u8f93\u5165\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528for\u5faa\u73af\u8f93\u5165<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>for<\/code>\u5faa\u73af\u904d\u5386\u4e00\u4e2a\u5217\u8868\uff0c\u5c06\u7528\u6237\u8f93\u5165\u7684\u6570\u636e\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fields = [&#39;\u59d3\u540d&#39;, &#39;\u5e74\u9f84&#39;, &#39;\u6027\u522b&#39;]<\/p>\n<p>person_info = {}<\/p>\n<p>for field in fields:<\/p>\n<p>    person_info[field] = input(f&quot;\u8bf7\u8f93\u5165{field}: &quot;)<\/p>\n<p>print(person_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>fields<\/code>\u5217\u8868\u5305\u542b\u4e86\u9700\u8981\u8f93\u5165\u7684\u5b57\u6bb5\u540d\u79f0\u3002<code>for<\/code>\u5faa\u73af\u904d\u5386\u8fd9\u4e2a\u5217\u8868\uff0c\u5e76\u901a\u8fc7<code>input()<\/code>\u51fd\u6570\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u5c06\u5176\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u5bf9\u5e94\u7684\u952e\u4e0a\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528while\u5faa\u73af\u8f93\u5165<\/h4>\n<\/p>\n<p><p><code>while<\/code>\u5faa\u73af\u4e5f\u53ef\u4ee5\u7528\u4e8e\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u7279\u522b\u9002\u5408\u4e8e\u9700\u8981\u52a8\u6001\u505c\u6b62\u8f93\u5165\u7684\u573a\u666f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {}<\/p>\n<p>while True:<\/p>\n<p>    key = input(&quot;\u8bf7\u8f93\u5165\u952e\u540d(\u6216\u8f93\u5165&#39;\u9000\u51fa&#39;\u7ed3\u675f): &quot;)<\/p>\n<p>    if key == &#39;\u9000\u51fa&#39;:<\/p>\n<p>        break<\/p>\n<p>    value = input(&quot;\u8bf7\u8f93\u5165\u503c: &quot;)<\/p>\n<p>    data[key] = value<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7528\u6237\u53ef\u4ee5\u6301\u7eed\u8f93\u5165\u952e\u503c\u5bf9\uff0c\u76f4\u5230\u8f93\u5165\u201c\u9000\u51fa\u201d\u6765\u7ed3\u675f\u5faa\u73af\u3002\u8fd9\u6837\u53ef\u4ee5\u52a8\u6001\u5730\u5b58\u50a8\u4e0d\u540c\u6570\u91cf\u7684\u8f93\u5165\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5b57\u5178\u63a8\u5bfc\u5f0f<\/h3>\n<\/p>\n<p><p>\u5b57\u5178\u63a8\u5bfc\u5f0f\u662f\u4e00\u79cd\u7b80\u6d01\u7684\u8bed\u6cd5\uff0c\u7528\u4e8e\u521b\u5efa\u5b57\u5178\u3002\u901a\u8fc7\u7ed3\u5408<code>input()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5feb\u901f\u7684\u8f93\u5165\u5b58\u50a8\u3002<\/p>\n<\/p>\n<p><h4>1. \u57fa\u4e8e\u5217\u8868\u7684\u5b57\u5178\u63a8\u5bfc\u5f0f<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6709\u4e00\u4e2a\u5df2\u77e5\u7684\u5b57\u6bb5\u5217\u8868\uff0c\u53ef\u4ee5\u7ed3\u5408\u5b57\u5178\u63a8\u5bfc\u5f0f\u5b9e\u73b0\u5feb\u901f\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">fields = [&#39;\u59d3\u540d&#39;, &#39;\u5e74\u9f84&#39;, &#39;\u6027\u522b&#39;]<\/p>\n<p>person_info = {field: input(f&quot;\u8bf7\u8f93\u5165{field}: &quot;) for field in fields}<\/p>\n<p>print(person_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5b57\u5178\u63a8\u5bfc\u5f0f\u901a\u8fc7\u904d\u5386<code>fields<\/code>\u5217\u8868\uff0c\u4e3a\u6bcf\u4e2a\u5b57\u6bb5\u83b7\u53d6\u7528\u6237\u8f93\u5165\u5e76\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>2. \u52a8\u6001\u521b\u5efa\u5b57\u5178<\/h4>\n<\/p>\n<p><p>\u4e5f\u53ef\u4ee5\u52a8\u6001\u5730\u521b\u5efa\u5b57\u5178\uff0c\u5141\u8bb8\u7528\u6237\u8f93\u5165\u4efb\u610f\u6570\u91cf\u7684\u952e\u503c\u5bf9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {input(&quot;\u8bf7\u8f93\u5165\u952e\u540d: &quot;): input(&quot;\u8bf7\u8f93\u5165\u503c: &quot;) for _ in range(int(input(&quot;\u8bf7\u8f93\u5165\u8981\u8f93\u5165\u7684\u952e\u503c\u5bf9\u6570\u91cf: &quot;)))}<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u7528\u6237\u9996\u5148\u8f93\u5165\u8981\u521b\u5efa\u7684\u952e\u503c\u5bf9\u6570\u91cf\uff0c\u7136\u540e\u9010\u4e2a\u8f93\u5165\u952e\u548c\u503c\uff0c\u6700\u7ec8\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u6240\u6709\u8f93\u5165\u6570\u636e\u7684\u5b57\u5178\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u7ed3\u5408\u51fd\u6570\u5b9e\u73b0\u8f93\u5165\u5b58\u50a8<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u5c06\u8f93\u5165\u548c\u5b58\u50a8\u903b\u8f91\u5c01\u88c5\u5230\u51fd\u6570\u4e2d\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u91cd\u7528\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u8f93\u5165\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u51fd\u6570\u6765\u5904\u7406\u5b57\u5178\u7684\u8f93\u5165\u548c\u5b58\u50a8\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def get_user_info():<\/p>\n<p>    fields = [&#39;\u59d3\u540d&#39;, &#39;\u5e74\u9f84&#39;, &#39;\u6027\u522b&#39;]<\/p>\n<p>    return {field: input(f&quot;\u8bf7\u8f93\u5165{field}: &quot;) for field in fields}<\/p>\n<p>user_info = get_user_info()<\/p>\n<p>print(user_info)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>get_user_info()<\/code>\u51fd\u6570\u8d1f\u8d23\u5904\u7406\u7528\u6237\u8f93\u5165\u5e76\u8fd4\u56de\u4e00\u4e2a\u5b57\u5178\u3002\u8c03\u7528\u8be5\u51fd\u6570\u65f6\uff0c\u4f1a\u63d0\u793a\u7528\u6237\u8f93\u5165\u76f8\u5173\u4fe1\u606f\uff0c\u5e76\u8fd4\u56de\u5305\u542b\u8fd9\u4e9b\u4fe1\u606f\u7684\u5b57\u5178\u3002<\/p>\n<\/p>\n<p><h4>2. \u5904\u7406\u591a\u7ec4\u8f93\u5165<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u5904\u7406\u591a\u7ec4\u7528\u6237\u8f93\u5165\uff0c\u53ef\u4ee5\u5728\u51fd\u6570\u4e2d\u4f7f\u7528\u5faa\u73af\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def get_multiple_user_info(n):<\/p>\n<p>    all_users = []<\/p>\n<p>    for _ in range(n):<\/p>\n<p>        user_info = get_user_info()<\/p>\n<p>        all_users.append(user_info)<\/p>\n<p>    return all_users<\/p>\n<p>num_users = int(input(&quot;\u8bf7\u8f93\u5165\u8981\u8f93\u5165\u7684\u7528\u6237\u6570\u91cf: &quot;))<\/p>\n<p>users = get_multiple_user_info(num_users)<\/p>\n<p>print(users)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>get_multiple_user_info()<\/code>\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u53c2\u6570<code>n<\/code>\uff0c\u8868\u793a\u8981\u8f93\u5165\u7684\u7528\u6237\u6570\u91cf\u3002\u901a\u8fc7\u8c03\u7528<code>get_user_info()<\/code>\u51fd\u6570\u83b7\u53d6\u6bcf\u4e2a\u7528\u6237\u7684\u4fe1\u606f\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5230\u4e00\u4e2a\u5217\u8868\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u5f0f\u5c06\u8f93\u5165\u6570\u636e\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002\u65e0\u8bba\u662f\u5904\u7406\u5c11\u91cf\u6570\u636e\u8fd8\u662f\u5927\u91cf\u6570\u636e\uff0cPython\u63d0\u4f9b\u4e86\u7075\u6d3b\u7684\u5de5\u5177\u548c\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u4e00\u4e2a\u5b57\u5178\u5e76\u8f93\u5165\u6570\u636e\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u82b1\u62ec\u53f7 <code>{}<\/code> \u6765\u521b\u5efa\u4e00\u4e2a\u5b57\u5178\u3002\u53ef\u4ee5\u901a\u8fc7\u76f4\u63a5\u6307\u5b9a\u952e\u503c\u5bf9\u6765\u8f93\u5165\u6570\u636e\u3002\u4f8b\u5982\uff0c<code>my_dict = {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25}<\/code> \u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u59d3\u540d\u548c\u5e74\u9f84\u7684\u5b57\u5178\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528 <code>dict()<\/code> \u51fd\u6570\uff0c\u5982 <code>my_dict = dict(name=&#39;Alice&#39;, age=25)<\/code>\u3002\u8f93\u5165\u6570\u636e\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>my_dict[&#39;name&#39;]<\/code> \u8bbf\u95ee\u5b57\u5178\u4e2d\u7684\u503c\u3002<\/p>\n<p><strong>\u5728Python\u5b57\u5178\u4e2d\u5982\u4f55\u66f4\u65b0\u5df2\u6709\u7684\u952e\u503c\u5bf9\uff1f<\/strong><br \/>\u8981\u66f4\u65b0\u5b57\u5178\u4e2d\u5df2\u6709\u7684\u952e\u503c\u5bf9\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7\u952e\u8fdb\u884c\u8d4b\u503c\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60f3\u5c06 <code>age<\/code> \u66f4\u65b0\u4e3a30\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>my_dict[&#39;age&#39;] = 30<\/code>\u3002\u8fd9\u6837\uff0c\u5b57\u5178\u4e2d\u7684\u503c\u4f1a\u88ab\u65b0\u503c\u66ff\u6362\u3002\u5982\u679c\u952e\u4e0d\u5b58\u5728\uff0c\u5219\u4f1a\u65b0\u589e\u8be5\u952e\u503c\u5bf9\u3002<\/p>\n<p><strong>\u5982\u4f55\u4ece\u7528\u6237\u8f93\u5165\u4e2d\u52a8\u6001\u521b\u5efa\u548c\u5b58\u50a8\u5b57\u5178\u6570\u636e\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528 <code>input()<\/code> \u51fd\u6570\u4ece\u7528\u6237\u83b7\u53d6\u8f93\u5165\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u8f93\u5165\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u5faa\u73af\u4e2d\u83b7\u53d6\u7528\u6237\u7684\u952e\u548c\u503c\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u5b57\u5178\u4e2d\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">my_dict = {}\nwhile True:\n    key = input(&quot;\u8bf7\u8f93\u5165\u952e\uff08\u6216\u8f93\u5165&#39;\u9000\u51fa&#39;\u7ed3\u675f\uff09\uff1a&quot;)\n    if key == &#39;\u9000\u51fa&#39;:\n        break\n    value = input(&quot;\u8bf7\u8f93\u5165\u503c\uff1a&quot;)\n    my_dict[key] = value\n<\/code><\/pre>\n<p>\u8fd9\u6837\uff0c\u7528\u6237\u53ef\u4ee5\u52a8\u6001\u5730\u8f93\u5165\u4efb\u610f\u6570\u91cf\u7684\u952e\u503c\u5bf9\uff0c\u6700\u7ec8\u5f62\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u5b57\u5178\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5c06\u8f93\u5165\u7684\u6570\u636e\u5b58\u50a8\u5230\u5b57\u5178\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528input()\u51fd\u6570\u83b7\u53d6\u7528\u6237\u8f93\u5165\uff0c\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":987182,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/987177"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=987177"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/987177\/revisions"}],"predecessor-version":[{"id":987186,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/987177\/revisions\/987186"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/987182"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=987177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=987177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=987177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}