try:
    print(begin.lower() + text.upper() + end.lower())
except (AttributeError, TypeError):
    raise AssertionError('Input variables should be strings')
Proper way to assert type of variable in Python