f = open(r'D:\金融数据获取\作业素材.txt',encoding='utf-8')
lines =f.readlines() #读取文档
line = lines[-3] #识别正文最后一句话
words = line.split(' ') #把每一个单词分开
word = words[-1] #识别本句中最后一个单词,str有8个(包括换行符)
word1 = word.replace('\n', '') #去除换行符
word2 = word1.replace('.', '') #去除分隔符
x = len(word2)
print('最后一个单词的长度为',round(x))
见注释