rgfewfger
This commit is contained in:
31
test.py
31
test.py
@@ -1,3 +1,28 @@
|
||||
print(abs(100 - 10))
|
||||
https://letsexchange.io/
|
||||
# 3923 3938 16 3932 3938 6
|
||||
class MyClass:
|
||||
def __init__(self):
|
||||
# 启动时自动执行的方法
|
||||
self.start()
|
||||
|
||||
def start(self):
|
||||
print("启动方法已执行")
|
||||
|
||||
def my_method(self):
|
||||
print("指定的方法正在执行")
|
||||
print(bfghsgrg)
|
||||
# 模拟可能出现的错误
|
||||
# 下面这行代码会触发一个异常,你可以根据需要注释掉它来测试正常情况
|
||||
# result = 1 / 0
|
||||
|
||||
def end(self):
|
||||
print("结束方法已执行")
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.end()
|
||||
|
||||
|
||||
# 使用 with 语句来调用这个类和方法
|
||||
with MyClass() as obj:
|
||||
obj.my_method()
|
||||
Reference in New Issue
Block a user