Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

assert in Python

📅 2012-Apr-24 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ assert, python ⬩ 📚 Archive

i = 99

# assert expression
assert 99 == i

# assert expression, message
assert 99 == i, "This is printed when this assert fails"
assert 99 == i, "Value of i is {}, not 99".format( i )

When an assert statement fails, AssertionError exception is raised. If the assert statement has a message, that message is printed along with the AssertionError message.

Tried with: Python 3.2.2