企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
1、设置默认值 ``` def print_welcome(first,last,middle=''): print "welcome,{},{},{}".format(first,last,middle) print "enjoy your stay!" print_welcome(first='james',last='Grinnell') print_welcome(first='katie',middle='alison',last='cunningham') ``` 2、返回值 ``` def get_total(items): total = 0 for item in items: total += item return total items = [1,2,3,4] item_total = get_total(items) print item_total ``` 3、可以返回多个值 ``` def get_square_and_cube(number): square = number ** 2 cube = number ** 3 return square,cube print get_square_and_cube(5) square,cube = get_square_and_cube(4) print square print cube ``` 4、验证程序健壮性,及时结束程序![] ``` def check_year(year): if len(year) != 4: print "{} is invalid as a year.".format(year) return print "Good that seems to work as a year!" check_year("80") ```