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

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

1.with 语句用法

2.with 语句用于自定义的类

class Myclass:
    def __enter__(self):
        print('enter is run')
    def  py1(self,):
        print('py1 is run')
    def _exit__(self,):
        print('exit is run',type,value,traceback) 
    
发布了8 篇原创文章 · 获赞 1 · 访问量 148

猜你喜欢

转载自blog.csdn.net/qq_44980274/article/details/104215332