我從這個Python代碼Python的錯誤「類型錯誤:類型 'NoneType' 對象沒有LEN()
def read_lines():
user_entries = []
contin = True
while contin == True:
user_input = input(str("Enter string or just press enter to finish: "))
user_entries.append(user_input)
if len(user_input) == 0:
contin = False
print(user_entries)
lines = read_lines()
print(lines)
ci = o
contin = True
while contin:
if ci == len(lines):
contin = False
else:
line = lines(ci, ci + 1)
ci = ci + 1
print(ci, line)
然後我得到這個錯誤...
Traceback (most recent call last):
File "test.py", line 8 in <module>
if ci == len(lines):
Type Error: object of type 'NoneType' has no len()
得到一個錯誤我不太確定爲什麼我得到這個錯誤,當它執行行打印(行)時,它返回None。這可能是問題,但我不知道如何解決它。
你定義的'read_lines()'函數不會返回任何東西到'lines',所以它是** None **。 – bhansa
不要忘記將任何答案標記爲[已回答](https://www.google.co.in/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwjf__iKnpnTAhXky4MKHeloBR8QFggZMAA&url=https%3A% 2F%2Fmeta.stackexchange.com%2Fquestions%2F5234%2Fhow-確實接受-一個應答工作&USG = AFQjCNE2e2orpogybVZU_sdJD6evWbT5Fw&BVM = bv.152174688,d.amc及CAD = RJA) – bhansa