python 判断key是否在字典里

h={"c":"d","f":"a"}
print h
print type(h)
if 'a' in h:
    print '11111111'
else:
    print '22222222'
	
	
C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/core/a26.py
{'c': 'd', 'f': 'a'}

22222222



h={"c":"d","f":"a"}
print h
print type(h)
if 'c' in h:
    print '11111111'
else:
    print '22222222'
	
C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/core/a26.py
{'c': 'd', 'f': 'a'}

11111111

 

你可能感兴趣的:(python,高级编程)