def printThese(a=None,b=None,c=None):
print(a, "is stored in a")
print(b, "is stored in b")
print(c, "is stored in c")
def printScore(student,*scores):
print(f"Student Name:{student}")
for score in scores:
print(score)
def printPetNames(owner,**pets):
print(f"Owner Name:{owner}")
for pet, name in pets.items():
print(f"{pet}:{name}")
# 不能将**kwargs置于*args前
def printMytest(owner,*args,**kwargs):
print("Owner:",owner)
for i in args:
print(i)
for k,v in kwargs.items():
print(f"{k}:{v}")
if __name__ == '__main__':
# printThese()
# printScore("jona",100,95,88,92)
# printPetNames("Jonathan", dog="Brock", fish=["Larry", "Curly", "Moe"], turtle="Shelldon")
printMytest("xxx",1,2,2,fruit="apple",ball=["basket","tennis","foot"],animal="cat")
python之*args和**kwargs
最新推荐文章于 2025-03-19 11:51:54 发布