this is my code :
a ={
'power':'力',
'magic':'魔',
'skill':'技'
}
b =['power','wwwww']
for i in b :
#print getattr(a,i)
print a[i] or 'default string'
and it show error :
Traceback (most recent call last):
File "a.py", line 13, in <module>
print a[i] or 'default string'
KeyError: 'wwwww'
how to print right thing in ‘a’ when loop ‘b’ , and show a default string when ‘a’ dont has it,
thanks
You can use .get()