if __name__ == '__main__':
value = 0
"""
python 断言语法
作用: 确保语句运行到这一行时, 满足条件 (value is not 0)
如不满足条件 (value is not 0), 则直接在终端报错: f'value is not {value}'
"""
assert value is not 0, f'value is not {value}'
"""
若 assert 判断条件不满足, 则之后的代码都不会再运行
"""
print("The three people's principles are alive and well")
""" 终端运行结果
D:\vnstudio\python.exe C:/Users/HIAPAD/Desktop/tqz_vnpy_futures/tqzpy_futures/test.py
Traceback (most recent call last):
File "C:/Users/HIAPAD/Desktop/tqz_vnpy_futures/tqzpy_futures/test.py", line 11, in <module>
assert value is not 0, f'value is not {value}'
AssertionError: value is not 0
Process finished with exit code 1
"""
量化交易之python篇 - 语法(断言) - assert简述
最新推荐文章于 2022-08-19 15:43:43 发布