python4.2参数传入
Posted lma0702
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python4.2参数传入相关的知识,希望对你有一定的参考价值。
#顺序传入参数
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参数传入的主要内容,如果未能解决你的问题,请参考以下文章