将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
功能会怎样?对(现在为空)函数的调用是否仍然存在,或者是否也被优化掉了?