學習筆記
#使用字典代替switch語句例子1
dict = {1:'一',2:'二',3:'三',4:'四',5:'五',6:'六',7:'日'}
n = int(input("請輸入一個整數(1-7)"))
if 1<=n<=7:
print("星期"+dict[n])
else:
print("輸入錯誤")
運行結果
請輸入一個整數(1-7)6
星期六
學習筆記
#使用字典代替switch語句例子1
dict = {1:'一',2:'二',3:'三',4:'四',5:'五',6:'六',7:'日'}
n = int(input("請輸入一個整數(1-7)"))
if 1<=n<=7:
print("星期"+dict[n])
else:
print("輸入錯誤")
請輸入一個整數(1-7)6
星期六
class MetaCls(type): def __new__(cls, *args, **kwargs): print("in MetaCls") # return super(Meta