python编程:从入门到实践 第八章


def desc(str1,str2='six six'):    #默认值参数必须置后

    print(str1+" want's to out put :"+str2+"\t")

desc(str1='zeus',str2='lighting')  #关键字实参



def getname(first,last,middle=''):
    return "Name:"+first+last+middle
name1=getname('wo','jiu','shuo')
name2=getname('zhe','me')
print(name1,  name2)

lis=[]
def func(li):
    for i in li:
        i=i+"six"

func(lis[:])   #传入列表副本防止其被修改

print("传递任意数量的实参")

def multi(*things):   #创建名为things的元组
    for i in things:
        print(str(i)+"ame")

multi('aasd','assssssd','sad',30.222,65)


print("以字典形式接受")
def multi_dir(first,last,**info):
    profile={}
    profile['first_name']=first
    profile['last_name']=last
    for key,val in info.items():
        profile[key]=val
    return profile







猜你喜欢

转载自blog.csdn.net/Big_Study_Father/article/details/89186416