import re t = open('作业一素材.txt', mode='r', encoding='utf-8') txt = t.read() lines = txt.splitlines() line = lines[-3] words = re.split("\s", line) word = words[-1][:-1] print("最后一个单词",word,"的长度是:",len(word))
先分行,然后找到最后一句,之后找到最后的字符,截取单词,后查长度