
m = {0:0, 1:1}
def func(n):
if n in m:
# to do something
이런 표현식이 보인다. 무슨 뜻이지?
We can test if a key is in a dictionary or not using the keyword in. Notice that the membership test is only for the keys and not for the values.
Dictionary에 key가 있는지 없는지 알기 위해서 in 키워드를 사용한다. value가 아니라 key를 검사하는데 사용하는 것을 주의해야 한다.
m = {0:0, 1:1}
def func(n):
if n in m:
print('The key, ' + str(n) + ', is in m')
else:
print('The key, ' + str(n) + ', is not in m')
func(1)
func(10)
The key, 1, is in m
The key, 10, is not in m