__debug__ 除錯功能為 true,assert 內的運算式結果為 false,則會引發錯誤assert 運算式, 參數
assert test, "some message"
# 等同於
if __debug__:
    if not test:
        raise AssertionError("some message")
with 通常用在具有固定開啟、關閉模式,例如讀取檔案上try finally,確保最後檔案會關閉 close() 以釋放資源with ... as .. :
with 這類型的物件為 Context Manager(上下文管理器、資源管理器、情境管理器)
__enter__ 與 __exit__ 兩個方法的 classtry:
    file = open("test.txt", "w")
    file.write("hello world")
finally:
    file.close()
# 等同於
with open("test.txt", "w") as f:
    f.write("hello world")
import traceback
# 必須先 import
   
try:  
    
except:  
    traceback.print_exc()
    # 可列出錯誤行數
過了一半,總算要來看看 class(類別)了!