{"id":168620,"date":"2022-04-16T16:36:22","date_gmt":"2022-04-16T08:36:22","guid":{"rendered":"http:\/\/www.idc.net\/help\/168620\/"},"modified":"2022-04-16T16:36:22","modified_gmt":"2022-04-16T08:36:22","slug":"%e5%90%8e%e6%b5%aa%e4%ba%91python%e6%95%99%e7%a8%8b%ef%bc%9a%e4%b8%80%e7%9c%8b%e5%b0%b1%e6%87%82%e7%9a%84python%e8%be%93%e5%85%a5%e5%92%8c%e8%be%93%e5%87%ba%e3%80%81%e6%a0%bc%e5%bc%8f%e5%8c%96","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/168620\/","title":{"rendered":"\u540e\u6d6a\u4e91Python\u6559\u7a0b\uff1a\u4e00\u770b\u5c31\u61c2\u7684Python\u8f93\u5165\u548c\u8f93\u51fa\u3001\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u65b9\u6cd5"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/oss.py.cn\/pycn\/upload\/article\/000\/000\/004\/5d2d9b8011e71241.jpg\" class=\"aligncenter\"><\/p>\n<p>\u7a0b\u5e8f\u7684\u8f93\u51fa\u53ef\u4ee5\u6709\u591a\u79cd\u5f62\u5f0f\uff1a\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u636e\u4ee5\u4eba\u7c7b\u53ef\u8bfb\u7684\u5f62\u5f0f\u6253\u5370\u5230\u5c4f\u5e55\u4e0a\uff0c\u6216\u8005\u5c06\u5176\u5199\u5165\u5230\u6587\u4ef6\u4e2d\u4ee5\u4f9b\u540e\u7eed\u4f7f\u7528\u3002<\/p>\n<p><strong>\u683c\u5f0f\u5316\u8f93\u51fa<\/strong><\/p>\n<p>\u8fc4\u4eca\u4e3a\u6b62\uff0c\u5728 Python \u4e2d\u5b58\u5728\u4e24\u79cd\u8f93\u51fa\u503c\u7684\u65b9\u6cd5\uff1a\u8868\u8fbe\u5f0f\u8bed\u53e5\u4ee5\u53ca print() \u51fd\u6570\u3002\uff08\u7b2c\u4e09\u79cd\u65b9\u6cd5\u662f\u4f7f\u7528\u6587\u4ef6\u5bf9\u8c61\u7684 write() \u65b9\u6cd5\uff1b\u6807\u51c6\u6587\u4ef6\u8f93\u51fa\u53ef\u4ee5\u53c2\u8003 sys.stdout \u65b9\u6cd5\uff0c\u5176\u8be6\u7ec6\u5185\u5bb9\u8bf7\u67e5\u9605\u5e93\u53c2\u8003\u624b\u518c\u3002\uff09<\/p>\n<p>\u901a\u5e38\uff0c\u76f8\u8f83\u4e8e\u7b80\u5355\u5730\u6253\u5370\u4ee5\u7a7a\u683c\u4e3a\u5206\u9694\u7b26\u7684\u503c\uff0c\u4f60\u4f1a\u60f3\u8981\u5bf9\u7a0b\u5e8f\u7684\u8f93\u51fa\u7ed3\u679c\u8fdb\u884c\u66f4\u591a\u7684\u683c\u5f0f\u63a7\u5236\u3002\u5728 Python \u4e2d\uff0c\u5b58\u5728\u5982\u4e0b\u51e0\u79cd\u683c\u5f0f\u5316\u8f93\u51fa\u7684\u65b9\u6cd5\uff1a<\/p>\n<p>\u4f7f\u7528 f-strings \u5b57\u7b26\u4e32\u3002\u8fd9\u7c7b\u5b57\u7b26\u4e32\u9700\u8981\u5728\u5f15\u53f7\u6807\u8bb0\u4e4b\u524d\uff0c\u4ee5 f \u6216\u8005 F \u4f5c\u4e3a\u5b57\u7b26\u4e32\u7684\u5f00\u5934\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528 { \u548c } \u5305\u88f9\u60f3\u8981\u5d4c\u5165\u5230\u5b57\u7b26\u4e32\u4e2d\u7684 Python \u8868\u8fbe\u5f0f\u3002\u8be5\u8868\u8fbe\u5f0f\u53ef\u4ee5\u662f\u67d0\u4e2a\u53d8\u91cf\u6216\u5b57\u9762\u503c \u3002<\/p>\n<pre>&gt;&gt;&gt;&nbsp;year&nbsp;=&nbsp;2016&nbsp;;&nbsp;event&nbsp;=&nbsp;'Referendum'\n&gt;&gt;&gt;&nbsp;f'Results&nbsp;of&nbsp;the&nbsp;{year}&nbsp;{event}'\n'Results&nbsp;of&nbsp;the&nbsp;2016&nbsp;Referendum'<\/pre>\n<p>str.format() \u662f\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u7684\u7b2c\u4e8c\u79cd\u65b9\u6cd5\u3002\u76f8\u8f83\u4e8e\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u9700\u8981\u4f60\u8fdb\u884c\u66f4\u591a\u7684\u64cd\u4f5c\u3002\u4f60\u4ecd\u7136\u53ef\u4ee5\u5728\u5b57\u7b26\u4e32\u4e2d\u4f7f\u7528 { \u548c } \u6765\u5185\u5d4c\u53d8\u91cf\uff0c\u4e5f\u53ef\u4ee5\u8fdb\u884c\u8be6\u7ec6\u7684\u683c\u5f0f\u5316\u8bbe\u8ba1\u3002\u4f46\u8fd9\u8981\u6c42\u4f60\u63d0\u4f9b\u4e0e\u4e4b\u5bf9\u5e94\u7684\u88ab\u683c\u5f0f\u5316\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5b57\u7b26\u4e32\u7684\u5207\u7247\u64cd\u4f5c\u548c\u8fde\u63a5\u64cd\u4f5c\u6765\u5b8c\u6210\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u5316\u5904\u7406\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u521b\u5efa\u4efb\u4f55\u4f60\u60f3\u8981\u7684\u683c\u5f0f\u5316\u5f62\u5f0f\u3002\u5728 string \u7c7b\u578b\u4e2d\uff0c\u5305\u542b\u4e86\u4e00\u4e9b\u80fd\u591f\u5c06\u5b57\u7b26\u4e32\u6309\u6307\u5b9a\u5217\u5bbd\u586b\u5145\u7684\u65b9\u6cd5\u3002<\/p>\n<p>\u5982\u679c\u4f60\u4ec5\u4ec5\u60f3\u8981\u5728\u8c03\u8bd5\u65f6\u6253\u5370\u67d0\u4e9b\u53d8\u91cf\uff0c\u800c\u4e0d\u8fdb\u884c\u683c\u5f0f\u5316\u8f93\u51fa\uff0c\u90a3\u4e48\u4f60\u4e5f\u53ef\u4ee5\u4f7f\u7528 repr() \u51fd\u6570\u6216\u8005 str() \u51fd\u6570\u5c06\u4efb\u610f\u503c\u8f6c\u5316\u6210\u5b57\u7b26\u4e32\u3002<\/p>\n<p>str() \u51fd\u6570\u80fd\u591f\u5c06\u503c\u4ee5\u4eba\u7c7b\u53ef\u8bfb\u7684\u5f62\u5f0f\u5448\u73b0\uff0c\u800c repr() \u51fd\u6570\u5219\u662f\u5c06\u503c\u4ee5\u89e3\u91ca\u5668\u53ef\u8bfb\u7684\u5f62\u5f0f\u5448\u73b0\uff08\u5982\u679c\u6ca1\u6709\u4e0e\u4e4b\u5bf9\u5e94\u7684\u8f6c\u6362\u8bed\u6cd5\uff0c\u5219\u4f1a\u4ea7\u751f SyntaxError \u5f02\u5e38\uff09\u3002\u82e5\u67d0\u4e2a\u5bf9\u8c61\u6ca1\u6709\u9002\u7528\u4e8e\u4eba\u7c7b\u53ef\u8bfb\u7684\u5f62\u5f0f\uff0c\u5219 str() \u51fd\u6570\u7684\u8fd4\u56de\u503c\u4e0e repr() \u51fd\u6570\u76f8\u540c\u3002\u5728 Python \u4e2d\uff0c\u8bf8\u5982\u6570\u503c\u3001\u6216\u8005\u662f\u94fe\u8868\u3001\u5b57\u5178\u8fd9\u6837\u7684\u7ed3\u6784\uff0c\u4e0a\u8ff0\u4e24\u79cd\u51fd\u6570\u5404\u81ea\u6709\u7edf\u4e00\u7684\u5448\u73b0\u65b9\u5f0f\u3002\u4f46\u662f\u5bf9\u4e8e\u5b57\u7b26\u4e32\uff0c\u4e0a\u8ff0\u4e24\u79cd\u51fd\u6570\u5404\u81ea\u6709\u72ec\u7279\u7684\u5448\u73b0\u65b9\u5f0f\u3002<\/p>\n<p>\u5982\u4e0b\u793a\u4f8b\uff1a<\/p>\n<pre>&gt;&gt;&gt;&nbsp;s&nbsp;=&nbsp;'Hello,&nbsp;world.'\n&gt;&gt;&gt;&nbsp;str(s)\n'Hello,&nbsp;world.'\n&gt;&gt;&gt;&nbsp;repr(s)\n\"'Hello,&nbsp;world.'\"\n&gt;&gt;&gt;&nbsp;str(1\/7)\n'0.14285714285714285'\n&gt;&gt;&gt;&nbsp;x&nbsp;=&nbsp;10&nbsp;*&nbsp;3.25\n&gt;&gt;&gt;&nbsp;y&nbsp;=&nbsp;200&nbsp;*&nbsp;200\n&gt;&gt;&gt;&nbsp;s&nbsp;=&nbsp;'The&nbsp;value&nbsp;of&nbsp;x&nbsp;is&nbsp;'&nbsp;+&nbsp;repr(x)&nbsp;+&nbsp;',&nbsp;and&nbsp;y&nbsp;is&nbsp;'&nbsp;+&nbsp;repr(y)&nbsp;+&nbsp;'...'\n&gt;&gt;&gt;&nbsp;print(s)\nThe&nbsp;value&nbsp;of&nbsp;x&nbsp;is&nbsp;32.5,&nbsp;and&nbsp;y&nbsp;is&nbsp;40000...\n&gt;&gt;&gt;&nbsp;#&nbsp;\u5bf9\u4e8e\u5b57\u7b26\u4e32\uff0crepr()&nbsp;\u51fd\u6570\u4f1a\u6dfb\u52a0\u5f15\u53f7\u4ee5\u53ca\u53cd\u659c\u6760\uff1a\n...&nbsp;hello&nbsp;=&nbsp;'hello,&nbsp;world\\n'\n&gt;&gt;&gt;&nbsp;hellos&nbsp;=&nbsp;repr(hello)\n&gt;&gt;&gt;&nbsp;print(hellos)\n'hello,&nbsp;world\\n'\n&gt;&gt;&gt;&nbsp;#&nbsp;repr()&nbsp;\u51fd\u6570\u7684\u53c2\u6570\u4e5f\u53ef\u4ee5\u662f\u67d0\u4e2a&nbsp;Python&nbsp;\u5bf9\u8c61\uff1a\n...&nbsp;repr((x,&nbsp;y,&nbsp;('spam',&nbsp;'eggs')))\n\"(32.5,&nbsp;40000,&nbsp;('spam',&nbsp;'eggs'))\"<\/pre>\n<p>string \u6a21\u5757\u5305\u542b Template \u7c7b\u6765\u63d0\u4f9b\u989d\u5916\u7684\u5728\u5b57\u7b26\u4e32\u4e2d\u5d4c\u5165\u53d8\u91cf\u7684\u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u4f7f\u7528\u5360\u4f4d\u7b26\uff0c\u6bd4\u5982 $x \u6765\u5185\u5d4c\u53d8\u91cf\uff0c\u53d8\u91cf\u7684\u503c\u5b58\u653e\u5728\u5b57\u5178\u4e2d\u3002\u8fd9\u79cd\u65b9\u6cd5\u5bf9\u5b57\u7b26\u4e32\u7684\u683c\u5f0f\u5316\u63a7\u5236\u8f83\u5c11\u3002<\/p>\n<p><strong>&nbsp;\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6587\u5b57<\/strong><\/p>\n<p>\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u6587\u5b57 \uff08\u7b80\u79f0 f-strings \uff09\u5141\u8bb8\u4f60\u5728\u5b57\u7b26\u4e32\u4e2d\u5305\u542b Python \u8868\u8fbe\u5f0f\u7684\u503c\uff0c\u65b9\u6cd5\u662f\u5728\u5b57\u7b26\u4e32\u524d\u9762\u52a0\u4e0a f \u6216\u8005 F \uff0c\u5e76\u5c06\u8868\u8fbe\u5f0f\u5199\u6210 {expression} \u683c\u5f0f\u3002<\/p>\n<p>\u5728\u8868\u8fbe\u5f0f\u540e\u9762\u53ef\u4ee5\u52a0\u4e0a\u683c\u5f0f\u8bf4\u660e\u7b26\u3002\u8fd9\u6837\u80fd\u591f\u66f4\u597d\u5730\u63a7\u5236\u8868\u8fbe\u5f0f\u503c\u7684\u8f93\u51fa\u683c\u5f0f\u3002\u4e0b\u9762\u7684\u4f8b\u5b50\u5c06 PI \u820d\u5165\u5230\u5c0f\u6570\u4f4d\u6570\u540e\u4e09\u4f4d\u3002<\/p>\n<pre>&gt;&gt;&gt;&nbsp;import&nbsp;math\n&gt;&gt;&gt;&nbsp;print(f'The&nbsp;value&nbsp;of&nbsp;pi&nbsp;is&nbsp;approximately&nbsp;{math.pi:.3f}.')<\/pre>\n<p>\u5728&nbsp;':'&nbsp;\u4e4b\u540e\u52a0\u4e0a\u4e00\u4e2a\u6574\u6570\u8868\u793a\u8be5\u5b57\u6bb5\u7684\u6700\u5c0f\u5b57\u7b26\u6570\uff0c\u8fd9\u5bf9\u4e8e\u5217\u6392\u5e8f\u5f88\u6709\u7528\u3002<\/p>\n<pre>&gt;&gt;&gt;&nbsp;table&nbsp;=&nbsp;{'Sjoerd':&nbsp;4127,&nbsp;'Jack':&nbsp;4098,&nbsp;'Dcab':&nbsp;7678}\n&gt;&gt;&gt;&nbsp;for&nbsp;name,&nbsp;phone&nbsp;in&nbsp;table.items():\n...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print(f'{name:10}&nbsp;==&gt;&nbsp;{phone:10d}')\n...\nSjoerd&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4127\nJack&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4098\nDcab&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;7678<\/pre>\n<p>\u4e5f\u53ef\u7528\u5176\u4ed6\u4fee\u9970\u7b26\u6765\u8f6c\u6362\u8981\u683c\u5f0f\u5316\u7684\u503c\u3002&nbsp;'!a'&nbsp;\u8868\u793a\u5e94\u7528&nbsp;ascii()\u51fd\u6570 \uff0c&nbsp;'!s'&nbsp;\u8868\u793a\u5e94\u7528&nbsp;str()&nbsp;\u51fd\u6570\uff0c \u53e6\u5916&nbsp;'!r'&nbsp;\u8868\u793a\u5e94\u7528&nbsp;repr()&nbsp;\u51fd\u6570\uff1a<\/p>\n<pre>&gt;&gt;&gt;&nbsp;animals&nbsp;=&nbsp;'eels'\n&gt;&gt;&gt;&nbsp;print(f'My&nbsp;hovercraft&nbsp;is&nbsp;full&nbsp;of&nbsp;{animals}.')\nMy&nbsp;hovercraft&nbsp;is&nbsp;full&nbsp;of&nbsp;eels.\n&gt;&gt;&gt;&nbsp;print('My&nbsp;hovercraft&nbsp;is&nbsp;full&nbsp;of&nbsp;{animals&nbsp;!r}.')\nMy&nbsp;hovercraft&nbsp;is&nbsp;full&nbsp;of&nbsp;'eels'.<\/pre>\n<p>\u6709\u5173\u8fd9\u4e9b\u683c\u5f0f\u89c4\u8303\u7684\u53c2\u8003\uff0c\u8bf7\u53c2\u9605\u53c2\u8003\u6307\u5357 \u6700\u5c0f\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u3002<\/p>\n<p><strong>format () \u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5<\/strong><\/p>\n<p>str.format() \u7684\u57fa\u672c\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>&gt;&gt;&gt;&nbsp;print('We&nbsp;are&nbsp;the&nbsp;{}&nbsp;who&nbsp;say&nbsp;\"{}!\"'.format('knights',&nbsp;'Ni'))\nWe&nbsp;are&nbsp;the&nbsp;knights&nbsp;who&nbsp;say&nbsp;\"Ni!\"<\/pre>\n<p>\u5176\u4e2d\u7684\u62ec\u53f7\u548c\u5b57\u7b26\uff08\u79f0\u4e3a\u683c\u5f0f\u5b57\u6bb5\uff09\u5c06\u7528\u4f20\u5165&nbsp;str.format()&nbsp;\u65b9\u6cd5\u4e2d\u7684\u5bf9\u8c61\u6765\u66ff\u6362\u3002\u62ec\u53f7\u4e2d\u7684\u6570\u5b57\u53ef\u7528\u4e8e\u8868\u793a\u4f20\u9012\u7ed9&nbsp;str.format()&nbsp;\u65b9\u6cd5\u7684\u5bf9\u8c61\u7684\u4f4d\u7f6e\u3002<\/p>\n<pre>&gt;&gt;&gt;&nbsp;print('{0}&nbsp;and&nbsp;{1}'.format('spam',&nbsp;'eggs'))\nspam&nbsp;and&nbsp;eggs\n&gt;&gt;&gt;&nbsp;print('{1}&nbsp;and&nbsp;{0}'.format('spam',&nbsp;'eggs'))\neggs&nbsp;and&nbsp;spam<\/pre>\n<p>\u5982\u679c\u5728&nbsp;str.format()&nbsp;\u65b9\u6cd5\u4e2d\u4f7f\u7528\u5173\u952e\u5b57\u53c2\u6570\uff0c\u5176\u503c\u7b49\u4e8e\u53c2\u6570\u540d\u79f0\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n<pre>&gt;&gt;&gt;&nbsp;print('This&nbsp;{food}&nbsp;is&nbsp;{adjective}.'.format(\n...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;food='spam',&nbsp;adjective='absolutely&nbsp;horrible'))\nThis&nbsp;spam&nbsp;is&nbsp;absolutely&nbsp;horrible.<\/pre>\n<p>\u4f4d\u7f6e\u548c\u5173\u952e\u5b57\u53c2\u6570\u53ef\u4ee5\u4efb\u610f\u7ec4\u5408\uff1a<\/p>\n<pre>&gt;&gt;&gt;&nbsp;print('The&nbsp;story&nbsp;of&nbsp;{0},&nbsp;{1},&nbsp;and&nbsp;{other}.'.format('Bill',&nbsp;'Manfred',\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;other='Georg'))\nThe&nbsp;story&nbsp;of&nbsp;Bill,&nbsp;Manfred,&nbsp;and&nbsp;Georg.<\/pre>\n<p>\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u4e0d\u60f3\u62c6\u5206\u7684\u957f\u5b57\u7b26\uff0c\u4f7f\u7528\u540d\u79f0\u800c\u4e0d\u662f\u4f4d\u7f6e\u6765\u8fdb\u884c\u683c\u5f0f\u5316\u5c06\u4f1a\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u65b9\u6cd5\u3002\u8fd9\u53ef\u4ee5\u7b80\u5355\u7684\u4f7f\u7528&nbsp;'[]'\u7b26\u53f7\u6765\u83b7\u53d6\u5b57\u5178\u4e2d\u7684\u952e<\/p>\n<pre>&gt;&gt;&gt;&nbsp;table&nbsp;=&nbsp;{'Sjoerd':&nbsp;4127,&nbsp;'Jack':&nbsp;4098,&nbsp;'Dcab':&nbsp;8637678}\n&gt;&gt;&gt;&nbsp;print('Jack:&nbsp;{0[Jack]:d};&nbsp;Sjoerd:&nbsp;{0[Sjoerd]:d};&nbsp;'\n...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'Dcab:&nbsp;{0[Dcab]:d}'.format(table))\nJack:&nbsp;4098;&nbsp;Sjoerd:&nbsp;4127;&nbsp;Dcab:&nbsp;8637678<\/pre>\n<p>\u4e0a\u9762\u7684\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u4f7f\u7528 '**' \u5c06\u5b57\u5178\u4e2d\u7684\u4fe1\u606f\u8fdb\u884c\u4f20\u9012\u3002<\/p>\n<pre>&gt;&gt;&gt;&nbsp;table&nbsp;=&nbsp;{'Sjoerd':&nbsp;4127,&nbsp;'Jack':&nbsp;4098,&nbsp;'Dcab':&nbsp;8637678}\n&gt;&gt;&gt;&nbsp;print('Jack:&nbsp;{Jack:d};&nbsp;Sjoerd:&nbsp;{Sjoerd:d};&nbsp;Dcab:&nbsp;{Dcab:d}'.format(**table))\nJack:&nbsp;4098;&nbsp;Sjoerd:&nbsp;4127;&nbsp;Dcab:&nbsp;8637678<\/pre>\n<p><strong>\u4f20\u7edf\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65b9\u6cd5<\/strong><\/p>\n<p>\u64cd\u4f5c\u7b26 '%' \u540c\u6837\u53ef\u4ee5\u88ab\u7528\u6765\u683c\u5f0f\u5316\u5b57\u7b26\u4e32\u3002\u5b83\u5c06\u8be5\u64cd\u4f5c\u7b26\u5de6\u4fa7\u53c2\u6570\u89e3\u91ca\u4e3a'sprintf ()' \u6837\u5f0f\u7684\u5b57\u7b26\u4e32\u5e94\u7528\u5230\u64cd\u4f5c\u7b26\u53f3\u4fa7\u53c2\u6570\uff0c\u5e76\u4e14\u8fd4\u56de\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>&gt;&gt;&gt;&nbsp;import&nbsp;math\n&gt;&gt;&gt;&nbsp;print('The&nbsp;value&nbsp;of&nbsp;pi&nbsp;is&nbsp;approximately&nbsp;%5.3f.'&nbsp;%&nbsp;math.pi)\nThe&nbsp;value&nbsp;of&nbsp;pi&nbsp;is&nbsp;approximately&nbsp;3.142.<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7a0b\u5e8f\u7684\u8f93\u51fa\u53ef\u4ee5\u6709\u591a\u79cd\u5f62\u5f0f\uff1a\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u636e\u4ee5\u4eba\u7c7b\u53ef\u8bfb\u7684\u5f62\u5f0f\u6253\u5370\u5230\u5c4f\u5e55\u4e0a\uff0c\u6216\u8005\u5c06\u5176\u5199\u5165\u5230\u6587\u4ef6\u4e2d\u4ee5\u4f9b\u540e\u7eed\u4f7f\u7528\u3002 \u683c\u5f0f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":168621,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[182397],"tags":[],"class_list":["post-168620","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/168620","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=168620"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/168620\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media\/168621"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=168620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=168620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=168620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}