{"id":1660,"date":"2023-07-15T09:23:38","date_gmt":"2023-07-15T01:23:38","guid":{"rendered":"http:\/\/zhang.mba\/?p=1660"},"modified":"2023-07-15T09:24:00","modified_gmt":"2023-07-15T01:24:00","slug":"mathfabsn1-n2","status":"publish","type":"post","link":"https:\/\/zhang.mba\/index.php\/2023\/07\/15\/09\/23\/38\/1660\/mathfabsn1-n2\/python\/zhangzhiqi\/","title":{"rendered":"math.fabs(n1 &#8211; n2)"},"content":{"rendered":"<p>\u5728\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0cmath.fabs() \u662f\u4e00\u4e2a math \u6a21\u5757\u4e2d\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u8fd4\u56de\u4e24\u4e2a\u6570\u503c\u7684\u7edd\u5bf9\u503c\u7684\u6d6e\u70b9\u6570\u3002<\/p>\n<p>\u4ee3\u7801\u89e3\u91ca\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">math.fabs(n1 - n2)\nmath \u662f\u4e00\u4e2a Python \u5185\u7f6e\u7684\u6570\u5b66\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u5404\u79cd\u6570\u5b66\u76f8\u5173\u7684\u51fd\u6570\u548c\u5e38\u91cf\u3002\nn1 \u548c n2 \u662f\u6570\u503c\u53d8\u91cf\uff0c\u53ef\u4ee5\u662f\u6574\u6570\u6216\u6d6e\u70b9\u6570\u3002\nmath.fabs() \u51fd\u6570\u63a5\u53d7\u4e00\u4e2a\u6570\u503c\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u8be5\u6570\u503c\u7684\u7edd\u5bf9\u503c\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5b83\u8ba1\u7b97\u4e86 n1 - n2 \u7684\u5dee\u503c\uff0c\u5e76\u8fd4\u56de\u5176\u7edd\u5bf9\u503c\u7684\u6d6e\u70b9\u6570\u3002\n\n<\/code><\/pre>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u8bf4\u660e\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-python\">import math\n\nn1 = 5\nn2 = 7\nresult = math.fabs(n1 - n2)\nprint(result)  # \u8f93\u51fa\u7ed3\u679c\u4e3a 2.0\n<\/code><\/pre>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d\uff0cn1 \u548c n2 \u7684\u5dee\u503c\u4e3a -2\uff0c\u4f7f\u7528 math.fabs() \u51fd\u6570\u8ba1\u7b97\u5176\u7edd\u5bf9\u503c\u5f97\u5230 2.0\uff0c\u5e76\u5c06\u7ed3\u679c\u8d4b\u503c\u7ed9\u53d8\u91cf result\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cmath.fabs() \u51fd\u6570\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u6d6e\u70b9\u6570\uff0c\u5373\u4f7f\u8f93\u5165\u662f\u6574\u6570\u3002\u5982\u679c\u9700\u8981\u6574\u6570\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528 abs() \u5185\u7f6e\u51fd\u6570\u6765\u8ba1\u7b97\u4e24\u4e2a\u6574\u6570\u7684\u7edd\u5bf9\u503c\u3002<\/p>\n<!--CusAds0-->\n<div style=\"font-size: 0px; height: 0px; line-height: 0px; margin: 0; padding: 0; clear: both;\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u5728\u63d0\u4f9b\u7684\u4ee3\u7801\u4e2d\uff0cmath.fabs() \u662f\u4e00\u4e2a math \u6a21\u5757\u4e2d\u7684\u51fd\u6570\uff0c\u7528\u4e8e\u8fd4\u56de\u4e24\u4e2a\u6570\u503c\u7684\u7edd\u5bf9\u503c\u7684\u6d6e\u70b9\u6570\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0},"categories":[12],"tags":[61],"_links":{"self":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1660"}],"collection":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/comments?post=1660"}],"version-history":[{"count":0,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/posts\/1660\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/media?parent=1660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/categories?post=1660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhang.mba\/index.php\/wp-json\/wp\/v2\/tags?post=1660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}