[python]assert文
条件に基づいてエラーメッセージを出力する場合、statement.
以下の構成を使用します.(ただし、メッセージは省略できます.)
たとえば、次のように使用できます.
以下の構成を使用します.(ただし、メッセージは省略できます.)
assert 조건문, message
デバッグモードでのみ動作する例外処理方法です.たとえば、次のように使用できます.
def check(a):
assert 3 <= a < 6, 'our of range'
この場合は下図のように記入すれば通過します.check(4)
逆に、範囲外の(8)を入力するとエラーが発生します.check(8)
Traceback (most recent call last):
File "/opt/ml/code/github/baseline/testcode.py", line 3, in <module>
check(7)
File "/opt/ml/code/github/baseline/testcode.py", line 2, in check
assert 3<=a <= 6, 'out of range'
AssertionError: out of range
Reference
この問題について([python]assert文), 我々は、より多くの情報をここで見つけました https://velog.io/@recoder/python-assert-문テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol