在使用函数时,我希望确保变量的类型符合预期。怎么做对?
这是一个伪函数示例,尝试在继续其作用之前执行此操作:
def my_print(begin, text, end):
    """Print 'text' in UPPER between 'begin' and 'end' in lower
    """
    for i in (begin, text, end):
        assert isinstance(i, str), "Input variables should be strings"
    out = begin.lower() + text.upper() + end.lower()
    print out
def test():
    """Put your test cases here!
    """
    assert my_print("asdf", "fssfpoie", "fsodf")
    assert not my_print("fasdf", 33, "adfas")
    print "All tests passed"
test()
断言是正确的方法吗?我应该改用try / except吗?
此外,我断言的一组测试似乎无法正常工作:S
谢谢pythoneers