나는 zed shaw의 저서 "learning python the hard way"를 읽고있다. 용서해주세요.하지만 저는 코딩의 초보자입니다. 그리고 이것을 이해하는 데 어려움을 겪고 있습니다. find_city 함수가 상태로 들어가서 반환 할 도시를 찾는 방법을 알 수없는 것 같습니다. !! "괜찮주의를 기울"이 라인은 지금까지 가장 중요하다 "#과 함께 선 연구는 나를 혼란 것들입니다 간단히책에서 교훈을 얻은 PYTHON 코드
cities = {'CA': 'San Francisco', 'MI': 'Detroit',
'FL': 'Jacksonville'}
cities['NY'] = 'New York'
cities['OR'] = 'Portland'
def find_city(themap, state):
if state in themap:
return themap[state]
else:
return "Not found."
# ok pay attention!
cities['_find'] = find_city
while True:
print "State? (ENTER to quit)",
state = raw_input("> ")
if not state: break
# this line is the most important ever! study!
city_found = cities['_find'](cities, state)
print city_found
이 * 특히 * 당신이 이해하지 않는 무엇? 설명을 업데이트하십시오. –
@ChrisMorgan이 말했듯이 사람들이 무엇을 추측해야할지 모르기 때문에 설명 할 특정 부분을 설명하면서 질문을 편집해야합니다. – jamylak
@ChrisMorgan 나는 그것을 이미 깨닫고 그것을 편집했다 : D – jamylak