{"id":74125,"date":"2026-02-09T06:09:49","date_gmt":"2026-02-08T22:09:49","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/74125.html"},"modified":"2026-02-09T06:09:49","modified_gmt":"2026-02-08T22:09:49","slug":"python3-operator%e6%a8%a1%e5%9d%97%e9%ab%98%e6%95%88%e4%bd%bf%e7%94%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/74125.html","title":{"rendered":"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357"},"content":{"rendered":"<h4>Python3 operator\u6a21\u5757\u5168\u9762\u5b66\u4e60\u6559\u7a0b<\/h4>\n<h5>\u4e00\u3001\u6a21\u5757\u6982\u8ff0<\/h5>\n<p>operator\u6a21\u5757\u4e3aPython\u7684\u5185\u7f6e\u8fd0\u7b97\u7b26\u63d0\u4f9b\u4e86\u51fd\u6570\u5f0f\u63a5\u53e3\u3002\u5b83\u5305\u542b\u4e0e\u6bd4\u8f83\u8fd0\u7b97\u3001\u903b\u8f91\u8fd0\u7b97\u3001\u6570\u5b66\u8fd0\u7b97\u7b49\u5bf9\u5e94\u7684\u51fd\u6570&#xff0c;\u53ef\u66ff\u4ee3lambda\u8868\u8fbe\u5f0f&#xff0c;\u63d0\u5347\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002<\/p>\n<h5>\u4e8c\u3001\u5e38\u7528\u51fd\u6570\u5206\u7c7b<\/h5>\n<h6>1. \u7b97\u672f\u8fd0\u7b97<\/h6>\n<p>import operator as op<\/p>\n<p>print(op.add(3, 5))       # 8 \u2192 \u52a0\u6cd5<br \/>\nprint(op.sub(10, 4))      # 6 \u2192 \u51cf\u6cd5<br \/>\nprint(op.mul(2, 6))       # 12 \u2192 \u4e58\u6cd5<br \/>\nprint(op.truediv(9, 3))   # 3.0 \u2192 \u771f\u9664\u6cd5<br \/>\nprint(op.floordiv(7, 2))  # 3 \u2192 \u53d6\u6574\u9664\u6cd5<br \/>\nprint(op.mod(13, 5))      # 3 \u2192 \u53d6\u6a21<br \/>\nprint(op.pow(2, 4))       # 16 \u2192 \u5e42\u8fd0\u7b97<\/p>\n<h6>2. \u6bd4\u8f83\u8fd0\u7b97<\/h6>\n<p>data &#061; [(&#039;Alice&#039;, 25), (&#039;Bob&#039;, 20), (&#039;Charlie&#039;, 30)]<br \/>\nsorted_data &#061; sorted(data, key&#061;op.itemgetter(1))  # \u6309\u5e74\u9f84\u5347\u5e8f\u6392\u5e8f<\/p>\n<p>print(op.eq(10, 10))    # True \u2192 \u7b49\u4e8e<br \/>\nprint(op.ne(7, 3))      # True \u2192 \u4e0d\u7b49\u4e8e<br \/>\nprint(op.lt(5, 8))      # True \u2192 \u5c0f\u4e8e<br \/>\nprint(op.le(6, 6))      # True \u2192 \u5c0f\u4e8e\u7b49\u4e8e<\/p>\n<h6>3. \u903b\u8f91\u8fd0\u7b97<\/h6>\n<p>print(op.not_(True))        # False \u2192 \u903b\u8f91\u975e<br \/>\nprint(op.and_(True, False)) # False \u2192 \u903b\u8f91\u4e0e<br \/>\nprint(op.or_(False, True))  # True \u2192 \u903b\u8f91\u6216<\/p>\n<h6>4. \u5e8f\u5217\u64cd\u4f5c<\/h6>\n<p>my_list &#061; [1, 2, 3, 4]<br \/>\nprint(op.concat([1,2], [3,4]))  # [1,2,3,4] \u2192 \u5e8f\u5217\u8fde\u63a5<br \/>\nprint(op.contains([10,20], 20)) # True \u2192 \u5305\u542b\u68c0\u6d4b<br \/>\nprint(op.countOf([5,5,5], 5))   # 3 \u2192 \u8ba1\u6570<\/p>\n<h5>\u4e09\u3001\u9ad8\u9636\u51fd\u6570\u5e94\u7528<\/h5>\n<h6>1. itemgetter \u5bf9\u8c61<\/h6>\n<p>get_second &#061; op.itemgetter(1)  # \u83b7\u53d6\u5e8f\u5217\u7b2c\u4e8c\u4e2a\u5143\u7d20<br \/>\nprint(get_second([&#039;a&#039;,&#039;b&#039;,&#039;c&#039;]))  # &#039;b&#039;<\/p>\n<p># \u591a\u7ea7\u6392\u5e8f\u793a\u4f8b<br \/>\nstudents &#061; [(&#039;Bob&#039;, &#039;B&#039;, 15), (&#039;Alice&#039;, &#039;A&#039;, 20), (&#039;Chris&#039;, &#039;B&#039;, 18)]<br \/>\nsorted_students &#061; sorted(students, key&#061;op.itemgetter(1, 2))<\/p>\n<h6>2. attrgetter \u5bf9\u8c61<\/h6>\n<p>class Person:<br \/>\n    def __init__(self, name, age):<br \/>\n        self.name &#061; name<br \/>\n        self.age &#061; age<\/p>\n<p>people &#061; [Person(&#039;Tom&#039;, 30), Person(&#039;Jerry&#039;, 25)]<br \/>\nget_age &#061; op.attrgetter(&#039;age&#039;)  # \u83b7\u53d6age\u5c5e\u6027<br \/>\nprint([get_age(p) for p in people])  # [30, 25]<\/p>\n<h6>3. \u51fd\u6570\u5f0f\u7f16\u7a0b<\/h6>\n<p>from functools import reduce<br \/>\nresult &#061; reduce(op.add, [1,2,3,4])  # \u7b49\u6548\u4e8e sum([1,2,3,4])<br \/>\nprint(result)  # 10<\/p>\n<p>http:\/\/my.tv.sohu.com\/us\/441191809\/699557154.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzE1NC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557159.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzE1OS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557321.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzMyMS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557097.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzA5Ny5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557174.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzE3NC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557406.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzQwNi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557283.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzI4My5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557345.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzM0NS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557289.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzI4OS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557193.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzE5My5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557429.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzQyOS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557436.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzQzNi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557621.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzYyMS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557629.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzYyOS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557454.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzQ1NC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557636.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzYzNi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557533.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzUzMy5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557538.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzUzOC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557400.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzQwMC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557705.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzcwNS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557720.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzcyMC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557560.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzU2MC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557497.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzQ5Ny5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557672.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzY3Mi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557744.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzc0NC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557752.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzc1Mi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557574.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzU3NC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557768.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzc2OC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557690.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzY5MC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557833.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzgzMy5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557902.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzkwMi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558012.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODAxMi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558018.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODAxOC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557912.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzkxMi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557857.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzg1Ny5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557862.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzg2Mi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557868.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzg2OC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557928.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1NzkyOC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558118.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODExOC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557881.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzg4MS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558056.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODA1Ni5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557891.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzg5MS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558140.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODE0MC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558142.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODE0Mi5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558205.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODIwNS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699557969.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1Nzk2OS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558159.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODE1OS5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558163.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODE2My5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558100.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODEwMC5zaHRtbA&#061;&#061;.html http:\/\/my.tv.sohu.com\/us\/441191809\/699558234.shtml https:\/\/tv.sohu.com\/v\/dXMvNDQxMTkxODA5LzY5OTU1ODIzNC5zaHRtbA&#061;&#061;.html \u00a0<\/p>\n<h5>\u56db\u3001\u5b9e\u7528\u6280\u5de7<\/h5>\n<li>\n<p>\u66ff\u4ee3lambda operator.add \u6bd4 lambda x,y: x&#043;y \u66f4\u9ad8\u6548<\/p>\n<p> # \u4f20\u7edf\u65b9\u5f0f<br \/>\nsorted(names, key&#061;lambda x: x[1])<\/p>\n<p># \u4f18\u5316\u65b9\u5f0f<br \/>\nsorted(names, key&#061;op.itemgetter(1))<\/p>\n<\/li>\n<li>\n<p>\u65b9\u6cd5\u8c03\u7528\u5668<\/p>\n<p> upper_all &#061; map(op.methodcaller(&#039;upper&#039;), [&#039;a&#039;,&#039;b&#039;,&#039;c&#039;])<br \/>\nprint(list(upper_all))  # [&#039;A&#039;,&#039;B&#039;,&#039;C&#039;]<\/p>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u8fd0\u7b97\u7b26<\/p>\n<p> def vector_add(v1, v2):<br \/>\n    return tuple(map(op.add, v1, v2))<\/p>\n<p>print(vector_add((1,2), (3,4)))  # (4,6)<\/p>\n<\/li>\n<h5>\u4e94\u3001\u6027\u80fd\u4f18\u52bf<\/h5>\n<p>\u5728\u5faa\u73af\u5bc6\u96c6\u578b\u64cd\u4f5c\u4e2d&#xff0c;operator\u6a21\u5757\u6bd4\u7b49\u4ef7\u7684lambda\u8868\u8fbe\u5f0f\u5feb\u7ea620%-30%&#xff1a;<\/p>\n<p>import timeit<\/p>\n<p>lambda_time &#061; timeit.timeit(<br \/>\n    &#039;sorted(data, key&#061;lambda x: x[1])&#039;,<br \/>\n    setup&#061;&#039;data&#061;[(i, i%10) for i in range(1000)]&#039;,<br \/>\n    number&#061;1000<br \/>\n)<\/p>\n<p>op_time &#061; timeit.timeit(<br \/>\n    &#039;sorted(data, key&#061;op.itemgetter(1))&#039;,<br \/>\n    setup&#061;&#039;import operator as op; data&#061;[(i, i%10) for i in range(1000)]&#039;,<br \/>\n    number&#061;1000<br \/>\n)<\/p>\n<p>print(f&#034;Lambda\u8017\u65f6: {lambda_time:.4f}s&#034;)<br \/>\nprint(f&#034;Operator\u8017\u65f6: {op_time:.4f}s&#034;)<\/p>\n<h5>\u516d\u3001\u603b\u7ed3<\/h5>\n<p>\u901a\u8fc7operator\u6a21\u5757\u53ef\u5b9e\u73b0&#xff1a;<\/p>\n<ul>\n<li>\u66f4\u6e05\u6670\u7684\u51fd\u6570\u5f0f\u7f16\u7a0b<\/li>\n<li>\u66f4\u9ad8\u6548\u7684\u5e8f\u5217\u64cd\u4f5c<\/li>\n<li>\u66f4\u4f18\u96c5\u7684\u5c5e\u6027\/\u5143\u7d20\u8bbf\u95ee<\/li>\n<li>\u66f4\u5feb\u901f\u7684\u8fd0\u7b97\u6267\u884c<\/li>\n<\/ul>\n<p>\u5efa\u8bae\u5728\u6d89\u53ca\u5927\u91cf\u7b80\u5355\u8fd0\u7b97\u7684\u573a\u666f\u4e2d\u4f18\u5148\u4f7f\u7528\u6b64\u6a21\u5757&#xff0c;\u4f46\u9700\u6ce8\u610f\u5728\u7b80\u5355\u8868\u8fbe\u5f0f\u573a\u666f\u4e2d\u76f4\u63a5\u4f7f\u7528\u8fd0\u7b97\u7b26\u53ef\u80fd\u66f4\u76f4\u89c2&#xff1a;<\/p>\n<p># \u7b80\u5355\u573a\u666f<br \/>\nx &#043; y   # \u4f18\u4e8e operator.add(x, y)<\/p>\n<p># \u590d\u6742\u573a\u666f<br \/>\nreduce(op.add, large_list)  # \u4f18\u4e8e reduce(lambda a,b: a&#043;b, large_list)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python3 operator\u6a21\u5757\u5168\u9762\u5b66\u4e60\u6559\u7a0b<br \/>\n\u4e00\u3001\u6a21\u5757\u6982\u8ff0<br \/>\noperator\u6a21\u5757\u4e3aPython\u7684\u5185\u7f6e\u8fd0\u7b97\u7b26\u63d0\u4f9b\u4e86\u51fd\u6570\u5f0f\u63a5\u53e3\u3002\u5b83\u5305\u542b\u4e0e\u6bd4\u8f83\u8fd0\u7b97\u3001\u903b\u8f91\u8fd0\u7b97\u3001\u6570\u5b66\u8fd0\u7b97\u7b49\u5bf9\u5e94\u7684\u51fd\u6570&#xff0c;\u53ef\u66ff\u4ee3lambda\u8868\u8fbe\u5f0f&#xff0c;\u63d0\u5347\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002<br \/>\n\u4e8c\u3001\u5e38\u7528\u51fd\u6570\u5206\u7c7b<br \/>\n1. \u7b97\u672f\u8fd0\u7b97<br \/>\nimport operator as opprint(op.add(3, 5))       # 8 \u2192 \u52a0\u6cd5<br \/>\nprint(op.sub(10, 4))      # 6 \u2192 <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,190],"topic":[],"class_list":["post-74125","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/74125.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Python3 operator\u6a21\u5757\u5168\u9762\u5b66\u4e60\u6559\u7a0b \u4e00\u3001\u6a21\u5757\u6982\u8ff0 operator\u6a21\u5757\u4e3aPython\u7684\u5185\u7f6e\u8fd0\u7b97\u7b26\u63d0\u4f9b\u4e86\u51fd\u6570\u5f0f\u63a5\u53e3\u3002\u5b83\u5305\u542b\u4e0e\u6bd4\u8f83\u8fd0\u7b97\u3001\u903b\u8f91\u8fd0\u7b97\u3001\u6570\u5b66\u8fd0\u7b97\u7b49\u5bf9\u5e94\u7684\u51fd\u6570&#xff0c;\u53ef\u66ff\u4ee3lambda\u8868\u8fbe\u5f0f&#xff0c;\u63d0\u5347\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002 \u4e8c\u3001\u5e38\u7528\u51fd\u6570\u5206\u7c7b 1. \u7b97\u672f\u8fd0\u7b97 import operator as opprint(op.add(3, 5))    # 8 \u2192 \u52a0\u6cd5 print(op.sub(10, 4))   # 6 \u2192\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/74125.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-08T22:09:49+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74125.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/74125.html\",\"name\":\"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-08T22:09:49+00:00\",\"dateModified\":\"2026-02-08T22:09:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/74125.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/74125.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/74125.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/74125.html","og_locale":"zh_CN","og_type":"article","og_title":"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Python3 operator\u6a21\u5757\u5168\u9762\u5b66\u4e60\u6559\u7a0b \u4e00\u3001\u6a21\u5757\u6982\u8ff0 operator\u6a21\u5757\u4e3aPython\u7684\u5185\u7f6e\u8fd0\u7b97\u7b26\u63d0\u4f9b\u4e86\u51fd\u6570\u5f0f\u63a5\u53e3\u3002\u5b83\u5305\u542b\u4e0e\u6bd4\u8f83\u8fd0\u7b97\u3001\u903b\u8f91\u8fd0\u7b97\u3001\u6570\u5b66\u8fd0\u7b97\u7b49\u5bf9\u5e94\u7684\u51fd\u6570&#xff0c;\u53ef\u66ff\u4ee3lambda\u8868\u8fbe\u5f0f&#xff0c;\u63d0\u5347\u4ee3\u7801\u53ef\u8bfb\u6027\u548c\u6267\u884c\u6548\u7387\u3002 \u4e8c\u3001\u5e38\u7528\u51fd\u6570\u5206\u7c7b 1. \u7b97\u672f\u8fd0\u7b97 import operator as opprint(op.add(3, 5))    # 8 \u2192 \u52a0\u6cd5 print(op.sub(10, 4))   # 6 \u2192","og_url":"https:\/\/www.wsisp.com\/helps\/74125.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-08T22:09:49+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/74125.html","url":"https:\/\/www.wsisp.com\/helps\/74125.html","name":"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-08T22:09:49+00:00","dateModified":"2026-02-08T22:09:49+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/74125.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/74125.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/74125.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python3 operator\u6a21\u5757\u9ad8\u6548\u4f7f\u7528\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=74125"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/74125\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=74125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=74125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=74125"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=74125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}