标签:
# -*- coding: cp936 -*-
#下面这个函数接受voltage为必选参数,其余三个为可选参数
def parrot(voltage,state=‘a stiff‘,action=‘voom‘,type=‘Norwegian Blue‘):
print("--This parrot wouldn‘t",action,end=‘ ‘)
print("if you put",voltage,"volts through it")
print("-- Lovely plumage,the",type)
print("-- It‘s",state,"!")
#在调用时,除了第一个必选参数以外,其他参数都要指明关键字,顺序不重要
parrot(223)
parrot(1000,action=‘kill‘)
parrot(10000,state=‘died‘)
parrot(10000,type=‘Chinese parrot‘,state=‘lively‘)
print("*"*40)
#下面这个函数包含字典数据类型
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()) #对关键字排序
for kw in keys:
print(kw, ":", keywords[kw])
#调用该测试函数
cheeseshop(‘sweet‘,"It‘s kind of you,Sir!",‘thank you!‘,name=‘zzw‘,age=‘20‘,sex=‘male‘)
标签:
原文地址:http://my.oschina.net/zzw922cn/blog/509110