将断言语句提取/重构/包装到单独的函数

时间:2016-01-26 10:27:07

标签: python assert

将assert语句包装到单独的函数中是否有意义?类似的东西:

def main1(x):
    assert 5 <= x <= 10, "value {} not in range [{},{}]".format(x,5,10)
    pass # do something 

VS

def assert_range(x,a,b):
    assert a <= x <= b, "value {} not in range [{},{}]".format(x,a,b)

def main2(x):
    assert_range(x,5,10)
    pass # do something 

据我所知,在优化编译中删除了assert语句。我的assert_range功能会怎样?对(现在为空)函数的调用是否仍然存在,或者是否也被优化掉了?

0 个答案:

没有答案