链式操作

5年以前  |  阅读数:997 次  |  编程语言:Python 
>>> from operator import (add, sub)
>>> def add_or_sub(a, b, oper):
 return (add if oper == '+' else sub)(a, b)
>>> add_or_sub(1, 2, '-')
-1

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8