学习笔记(10):Python 面试100讲(基于Python3.x)-请使用代码描述with语句的作用

立即学习:https://edu.csdn.net/course/play/26755/340159?utm_source=blogtoedu

with语句可以确保不管是否抛出异常,都会释放资源。如果将with语句用于自定义类中,需要实现__enter__和__exit__方法,否则会抛出异常

发布了17 篇原创文章 · 获赞 0 · 访问量 179

猜你喜欢

转载自blog.csdn.net/weixin_43745945/article/details/104196749