import re h = open('作业一素材.txt',mode='r', encoding='utf-8') content = h.read() lines = content.splitlines() phase = lines[-3] x = re.findall(r'\s(\w*).$', phase) len_x = len(x[0]) print(len_x)