我正在尝试编写一个代码,使每行的第一个字母都大写,但它无法执行到第 6 行之后if l[0].islower():。当它l[0]在循环之外时工作正常,但当我将其放回循环中时总是显示“字符串索引超出范围”。
m = open(r"C:\Users\■■■■■■\Desktop\■■■■\other.txt","r", encoding = "utf-8") #Just blocking the text out
while True:
l = m.readline()
if l[0].islower():
l.replace(l[0],l[0].upper())
print(l)
if not l:
break
m.close()
芜湖不芜
元芳怎么了
SMILET
相关分类