1 with open('shell','r+') as f: 2 for index,i in enumerate(f): 3 print(index,i.strip()) #Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)。