码迷,mamicode.com
首页 > 编程语言 > 详细

python4.2参数传入

时间:2019-06-30 13:53:26      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:img   形参   默认   实参   src   code   pytho   turn   name   

#顺序传入参数
def show(name,age,sex,hobby):#形参
print("我叫:",name,"年龄:",age,"性别:",sex,"爱好:",hobby)
show("张三",18,"男","打球")#实参(实参与形参一一对应)

#关键词传入参数
def show(name,age,sex,hobby):#形参
print("我叫:",name,"年龄:",age,"性别:",sex,"爱好:",hobby)
show(name="张三",sex="男",age=19,hobby="打球") #实参关键词传入


#关键词传入参数
def show(name,age,sex,hobby="打0球"):#形参默认参数hobby
print("我叫:",name,"年龄:",age,"性别:",sex,"爱好:",hobby)
show(name="张三",sex="男",age=19) #实参


#不定长参数传入
def add(*ars):
sum1=0
for i in ars:
sum1=sum1+i
return sum1
print(add(32,32,43))

技术图片

 

python4.2参数传入

标签:img   形参   默认   实参   src   code   pytho   turn   name   

原文地址:https://www.cnblogs.com/lma0702/p/11109378.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!