本文主要是介绍python学习5---fiction,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
# 默认参数
def repeat_str(s,times =2):repeated_strs =s*timesreturn repeated_strsrepeated_string = repeat_str("happy birthday! ")
print(repeated_string)
# 覆盖默认参数
repeated_string = repeat_str("happy birthday! ",4)
print(repeated_string)
repeated_string = repeat_str("happy birthday! ",)
print(repeated_string)#def fuc(a,b=4,c=8):print("a is ",a,"and b is ",b,"and c is ",c)fuc(13,17)
# 跳过b赋值
fuc(125,c = 24)
fuc(c=23,a=1)
# 有点类似与参数的指针,*对应的list,**对应字典
def print_paras(fpara, *nums, **words):print("fpara: "+str(fpara))print("nums "+str(nums))print("words: "+str(words))print_paras("hello",1,3,5,7,word ="python",anathor_word ="java")
这篇关于python学习5---fiction的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!