请您检查一下这段代码,为什么 python 中出现“unsupported operand type(s) for -: 'str' and 'int'”这个错误。
代码:
def missing_char(str, n):
check = len(str -1)
if check < n or n < 0:
return False
else:
front = str[:n]
back = str[n+1:]
return front + back
最佳答案
你把)
放在了错误的地方,- 1
应该在它的外面:
def missing_char(str, n):
check = len(str) - 1
if check < n or n < 0:
return False
else:
front = str[:n]
back = str[n+1:]
return front + back
关于python - 您能检查一下 "unsupported operand type(s) for -: ' str' 和 'int' ",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54274274/