Quick actions

cmd+k|ctrl+k

Navigation

Languages

example: try, raise, assert, except 22/5

Snippet info

Language

Python

Visibility

public

Author

tonyngswell

Created

2026-05-21T13:49:01.566854Z

Updated

2026-05-21T13:49:01.566854Z

''' assert expression
=> if not expression:
      raise AssertionError
      
assert exp1, exp2
=> if not exp1:
      raise AssertionError(exp2)
'''
def a():
    print("function a")
    return False
try:    #https://glot.io/snippets/hhrnbqy42s
    x = 1
    y = x + 1
    if y == 2:
        assert a(), 'assertion error'
except AssertionError as msg:
    print(msg)
      

INFO