美文网首页
python中print和return的区别

python中print和return的区别

作者: 蓝剑狼 | 来源:发表于2018-10-17 00:15 被阅读23次

    return是返回值 print是打印输出
    return后面的代码是不执行的

    goods_dict = {
    
        "001": {"name": "MacBook Pro", "price": 14999},
        "002": {"name": "欧米茄手表 ", "price": 11111},
        "003": {"name": "小米笔记本 ", "price": 4999},
        "004": {"name": "Ipad mini2 ", "price": 1998},
        "005": {"name": "小米8手机  ", "price": 2998},
        "006": {"name": "爱马仕腰带 ", "price": 1999},
        "007": {"name": "劳力士男表 ", "price": 19999},
        "008": {"name": "巴宝莉眼镜 ", "price": 4999},
        "009": {"name": "路虎发现四 ", "price": 99999},
    }
    
    
    def num_in_goods_list(n):
        for num in goods_dict:
            if n == num:
                return True
        return False
        print("看你执行不")
    
    
    print("1".center(30, "*"))
    print(num_in_goods_list("001"))
    print("2".center(30, "*"))
    print(num_in_goods_list("uuu"))
    
    
    def num_in_goods_list_1(n):
        for num in goods_dict:
            if n == num:
                print("编码存在")
        print("编码不存在")
        print("看你执行不")
    
    
    print("3".center(30, "*"))
    num_in_goods_list_1("001")
    print("4".center(30, "*"))
    num_in_goods_list_1("uuu")
    # 代码执行结果
    **************1***************
    True
    **************2***************
    False
    **************3***************
    编码存在
    编码不存在
    看你执行不
    **************4***************
    编码不存在
    看你执行不
    

    相关文章

      网友评论

          本文标题:python中print和return的区别

          本文链接:https://www.haomeiwen.com/subject/gvokzftx.html