我正在尝试编写一个带有仅接受字符串的函数的程序。如何使 python 函数参数始终为字符串,如果不是则抛出错误?
我正在寻找类似的东西:
def foo(i: int): return i foo(5) foo('oops')
但这不会引发错误。
python string types casting assertion
assertion ×1
casting ×1
python ×1
string ×1
types ×1