• slider image 221
:::

2-1 函數--任意參數數量

任意數量


def make_pizza(*toppings):
    """打印顧客點的所有配料"""
    print(toppings)

make_pizza('pepperoni')
make_pizza('mushrooms', 'green peppers', 'extra cheese')

 

def build_profile(first, last, **user_info):
    """創建一個字典,其中包含我們知道的有關用戶的一切"""
    profile = {}
    profile['first_name'] = first
    profile['last_name'] = last
    for key, value in user_info.items():
        profile[key] = value
        return profile

user_profile = build_profile('albert', 'einstein',
                               location='princeton',
                               field='physics')
print(user_profile)

 


Google網站翻譯工具列

站內搜尋