如何标记/分离函数中传递的输入?
例如,如果12356
作为输入传递,我想访问第三个符号,也就是3
,我该怎么办?
我在函数中尝试了以下代码,但出现了错误:
print(s[2]) IndexError: 'int' object is not subscriptable
代码:
def s_test(input):
s=input
print(s)
print(s[2])
s_test(12356)
在另一个程序中,当我执行同样的操作时,我得到一个错误:
"IndexError: string index out of range" for the instruction print(s[2])
谢谢
主要问题有以下几点。你知道吗
您正在这种类型的列表
["", "0", "1", "9", "10", "11", "12", "13"]
上执行for
循环,该列表在first
元素中包含1
空字符串。因此在第一次迭代中,一个空值被传递给NDRecognize(input, dates))
函数到每个for
循环中。这就是NDRecognize(input, dates))
函数出错的原因。你知道吗我希望你明白我在说什么。非常感谢。你知道吗
相关问题 更多 >
编程相关推荐