【发布时间】:2022-02-03 07:14:57
【问题描述】:
TypeError:“NoneType”类型的参数不可迭代 哪个变量是 NoneType? 是空列表 NoneType 吗?
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
if s=="":
return 0
max = 0
cur = 0
l = []
for ch in s:
if ch not in l:
cur += 1
l.append(ch)
else:
if cur > max:
max = cur
cur = 1
l = [].append(ch)
return max
【问题讨论】:
-
l = [].append(ch)=>l = [ch] -
那行得通,非常感谢,但为什么呢?我认为 [] 是一个列表对象,所以它有 append 方法。
-
欢迎来到 Stack Overflow。 “NoneType 是哪个变量?” 嗯,你有没有试过?例如,通过使用调试器,或者通过
printing 整个程序的变量值?请阅读ericlippert.com/2014/03/05/how-to-debug-small-programs。
标签: python python-3.x