代码来自Learn Python The Hard Way Exercise 39。请在第一组代码下方查看我的问题。
# create a mapping of state to abbreviation
states = {
'Oregon': 'OR',
'Florida': 'FL',
'California': 'CA',
'New York': 'NY',
'Michigan': 'MI'
}
# create a basic set of states and some cities in them
cities = {
'CA': 'San Francisco',
'MI': 'Detroit',
'FL': 'Jacksonville'
}
# do it by using the state then cities dict
print '-' * 10
print "Michigan has: ", cities[states['Michigan']]
print "Florida has: ", cities[states['Florida']]
当您可以像下面这样简单地进行打印时,为什么要以上述方式打印出来?
print '-' * 10
print "Michigan has: ", cities['MI']
print "Florida has: ", cities['FL']
我想知道我是否在这里遗漏了一些重要的东西。仅仅是为了学习目的吗?如果是这样,我究竟在那里学习什么?请澄清。