你好,我是 python 新手,我想知道是否可以创建一个只接受某些类型的值的函数,在本例中是字符串,否则错误
parameter that needs to be string
|
v
def isfloat(a):
if a.count('.') > 1:
return False
for c in a:
if c.isnumeric() or c == '.':
v = True
else:
return False
return v
Run Code Online (Sandbox Code Playgroud)