1.列表 # Filename: using_list.py # This is my shopping list shoplist=["apple", "mango", "carrot", "banana"] print ("I have", len(shoplist), "items to purchase.") print ("These items are:"…
1.列表和字典的迭代 程序开发中,对列表和字典进行迭代是非常常见的事情. 字典一般可以选择对key进行迭代.对value迭代和对key/value一起迭代 >>> d = {'a': 1, 'b': 2, 'c': 3} >>> for key in d: ... print(key) ... a c b 如果要迭代value,可以用for value in d.values(),如果要同时迭代key和value,可以用for k, v in d.items() 列表的…