Programing

사전에 특정 키가 포함되어 있는지 테스트하는 방법?

lottogame 2020. 4. 10. 08:06
반응형

사전에 특정 키가 포함되어 있는지 테스트하는 방법? [복제]


가능한 중복 :
파이썬 사전에 키가 있는지 테스트하는 좋은 방법은 무엇입니까?

사전에 키가 있는지 테스트하는 가장 깨끗한 방법은 무엇입니까?

x = {'a' : 1, 'b' : 2}
if (x.contains_key('a')):
    ....

'a' in x

빠른 검색은 그것에 대한 좋은 정보를 보여줍니다 : http://docs.python.org/3/tutorial/datastructures.html#dictionaries

참고 URL : https://stackoverflow.com/questions/5312778/how-to-test-if-a-dictionary-contains-a-specific-key

반응형