猪肝
2021-06-03 17:54
def info(**kwargs): names = kwargs['names'] gender_list = kwargs['gender'] age_list = kwargs['age'] index = 0 for name in names: gender = gender_list[index] age = age_list[index] print('name: {}, gender: {}, age: {}'.format(name, gender, age)) index += 1 info(names = ['Alice', 'Bob', 'Candy'], gender = ['girl', 'boy', 'girl'], age = [16, 17, 15])
鹅鹅鹅
names = kwargs['names'] # 入参取值,意思是调用info方法时会传入参数名为names的参数 gender_list = kwargs['gender'] # 同上 age_list = kwargs['age'] # 同上 index = 0 # 定义一个索引用于获取 names、gender_list、age_list参数列表中的对应索引值。 for name in names: # 遍历names列表 gender = gender_list[index] # 取值列表中索引为index 的值 age = age_list[index] print('name: {}, gender: {}, age: {}'.format(name, gender, age))#打印值 index += 1 # 索引+1
Python3 入门教程(新版)
154167 学习 · 1075 问题
相似问题