注册 登录
编程论坛 Python论坛

函数调用打印结果不完全

aa2820981 发布于 2019-07-26 09:43, 1226 次点击
代码如下:
# -*-coding:gb2312 -*-
def build_carinfo(brand,name,**car_info):
    profile= {}
    profile['brand_name'] = brand
    profile['car_name'] = name
    for key,value in car_info.items():
        profile[key] = value
        return profile
        
car_profile = build_carinfo('audi','a4',car_typy='limousine',drive_type='gas')
print(car_profile)
结果打印为:
{'brand_name': 'audi', 'car_name': 'a4', 'car_typy': 'limousine'}
为什么少了一项?求大神帮助!!
2 回复
#2
wp2319572019-07-26 10:51
回复 楼主 aa2820981
return profile  这个位置不正确   自己想一想  函数的返回值 应该和谁是一个层次的
#3
aa28209812019-07-26 20:09
回复 2楼 wp231957
懂了,谢谢!
1