pythontask 9

mac2024-04-11  42

else与with 语句 1 丰富的else 语句 while else 语句 for…else 语句 else会在If执行完之后执行(除break跳出) try …except…else try无异常执行else否则执行except后面语句 2 简洁with语句 (清理行为) 保证设定的文件对象在使用完之后会执行清理它的方法

try: with open('a.txt','w')as f: for line in f: print (line) except OSError as error: print('出错啦!%s' % srt(error)) #出错啦!not readable
最新回复(0)