考慮以下幾點:是否更好的方法來檢查變量是否在字典中,變量是否等於字典鍵?
variable = "TELKOM"
registry = {,
"CELLC": CellCSubscriber,
"TELKOM": TelkomSubscriber,
"HELLO MOBILE": HelloMobile,
"VODACOM": VodacomSubscriber,
"MTN": MTNSubscriber,
}
for k, v in registry:
if variable == k and variable == "TELKOM":
#do something to variable
有沒有更好的方式來做到這一點?
我雖然的:
if variable in registry:
#do something to variable
但隨着這個問題是,我沒有比較它"TELKOM", or am I wrong?
我不明白你的問題? '如果變量=='TELKOM'和變量在註冊表中:' – RedX