有人能告诉我这个python代码出了什么问题吗?看起来很傻,因为代码非常简单,但我是编码的初学者,希望可以理解.
f = open("countries.txt", "r")
countries = []
for line in f:
line = line.strip()
countries.append(line)
f.close()
print(countries)
print(len(countries))
for country in countries:
if country[0] == "T":
print(country)
Run Code Online (Sandbox Code Playgroud)
我一直收到以下错误:
line 16, in <module>
if country[0] == "T":
IndexError: string index out of range
Run Code Online (Sandbox Code Playgroud)