小编Syt*_*tze的帖子

Python 确保函数参数始终是字符串

我正在尝试编写一个带有仅接受字符串的函数的程序。如何使 python 函数参数始终为字符串,如果不是则抛出错误?

我正在寻找类似的东西:

def foo(i: int): 
       return i  
foo(5) 
foo('oops')
Run Code Online (Sandbox Code Playgroud)

但这不会引发错误。

python string types casting assertion

3
推荐指数
1
解决办法
742
查看次数

标签 统计

assertion ×1

casting ×1

python ×1

string ×1

types ×1