指针与词典

'''
"arguments"是一个指针变量,指向“*arguments”指向的值为:"It's very runny, sir.",
           "It's really very, VERY runny, sir."
引入一个形如 **keywords 的参数时,它接收一个字典{ shopkeeper="Michael Palin",
           client="John Cleese",
           sketch="Cheese Shop Sketch")
}
'''


def cheeseshop(kind, *arguments, **keywords):
    print("-- Do you have any", kind, "?")
    print("-- I'm sorry, we're all out of", kind)
    for arg in arguments:
        print(arg)
    print("-" * 40)
    keys = sorted(keywords.keys())  #sorted对列表中的元素进行排序
    for kw in keys:
        print(kw, ":", keywords[kw])
cheeseshop("Limburger", "It's very runny, sir.",
           "It's really very, VERY runny, sir.",
           shopkeeper="Michael Palin",
           client="John Cleese",
           sketch="Cheese Shop Sketch")

你可能感兴趣的:(Python学习)