def hello(name): return 'hello, '+name print(hello('jack')) def fibs(num): '计算斐波那契数'#文档字符串 a=[0,1] for i in range(int(num)-2): a.append(a[-1]+a[-2]) return a print(fibs(5)) def init(data): data['first']={} data['middle']={} data['last']={} def lookup(data,label,name): return data[label].get(name) def store(data,full_name): names=full_name.split() if len(names)==2:names.insert(1,'') labels={'first','middle','last'} for label,name in zip(labels,names): people=lookup(data,label,name) if people: data[label][name].append(full_name) else: data[label][name]=[full_name] MyName={} init(MyName) store(MyName,'ge da ya') store(MyName,'pi ka qiu') store(MyName,'pi zhi qing') print(lookup(MyName,'last','pi')) def show(name,*house,**cats):# *收集参数,存于元组中; **关键字参数,存于字典中 print(name) print(house) print(cats) show('帐单',1,2,3,4,5,huang=1,lv=2)