Python将单词的首字母转变成大写

注:部分内容来自书籍或者网络,如有侵权,请联系删除。

方法一

with open('data.txt') as inf,open('out.txt','w') as outf:
    for line in inf:
        outf.write(" ".join([word.capitalize() for word in line.split()]))

方法二

with open('data.txt') as inf,open('out.txt','w') as outf:
    for line in inf:
        print(*[word.capitalize() for word in line.split()],file=outf)


「 文章如果对你有帮助,请点个赞哦^^ 」 

0