assert isinstance python code example
Example 1: assert syntax python
assert <condition>,<error message>
#The assert condition must always be True, else it will stop execution and return the error message in the second argument
assert 1==2 , "Not True" #returns 'Not True' as Assertion Error.
Example 2: assert vs validate in python
from types import IntType, StringType
def some_func(int_arg, str_arg, other_arg):
assert type(int_arg) == IntType, "id is not an integer: %r" % int_arg
assert type(str_arg) == StringType or not str_arg
assert other_arg in (VALUE1, VALUE2, VALUE3), "other arg must be VALUE1, VALUE2, or VALUE3"