learn python the hard way exercise 40 help

后端 未结 1 878
傲寒
傲寒 2021-01-07 00:08

hey guys i am having trouble understanding this, i dont get when themap is referenced to the cities dict really. or the last line, what is the(cities, state) part?

t

相关标签:
1条回答
  • 2021-01-07 00:56

    cities['_find'] is exactly find_city. So cities['_find'](cities, state) is the same as find_city(cities, state).

    The reason for my first statement is this line:

    cities['_find'] = find_city
    

    That doesn't call find_city, it sticks the function itself in the dictionary. Python functions are just objects like lists and class instances. If you don't put parentheses after them, they can be assigned to variables.

    0 讨论(0)
提交回复
热议问题