python-small-examples/md/58.md at master · data-python/python-small-examples

Skip to content

Navigation Menu

Sign in

Appearance settings

Latest commit

File metadata and controls

18 lines (12 loc) · 242 Bytes

@author jackzhenguo
@desc 
@date 2019/3/23

58 operator使用举例

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