标题:函数调用打印结果不完全
只看楼主
aa2820981
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2019-7-16
结帖率:100%
已结贴  问题点数:20 回复次数:2 
函数调用打印结果不完全
代码如下:
# -*-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'}
为什么少了一项?求大神帮助!!
搜索更多相关主题的帖子: 函数 调用 打印 结果 profile 
2019-07-26 09:43
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:版主
威 望:422
帖 子:13681
专家分:53296
注 册:2012-10-18
得分:20 
回复 楼主 aa2820981
return profile  这个位置不正确   自己想一想  函数的返回值 应该和谁是一个层次的

DO IT YOURSELF !
2019-07-26 10:51
aa2820981
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2019-7-16
得分:0 
回复 2楼 wp231957
懂了,谢谢!
2019-07-26 20:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-496041-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.544054 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved