Study Notes (10): Python Interview 100 talking about (based Python3.x) - use the code describes the role of the with statement

Learning immediately: https://edu.csdn.net/course/play/26755/340159?utm_source=blogtoedu

with the statement ensures that regardless of whether an exception is thrown, it will free up resources. If the statement is used with a custom class, we need to realize __enter__ and __exit__ method, otherwise it will throw an exception

Published 17 original articles · won praise 0 · Views 179

Guess you like

Origin blog.csdn.net/weixin_43745945/article/details/104196749