Skip to main content
 首页 » 编程设计

python之python中的*是什么意思

2025年05月04日29kuangbin

<分区>

我有下一个问题。

item = [item.export_simple() 
            for item in session.query(Item) 
                               .filter(and_( 
                                       Item.companyId == company_id, 
                                       or_( 
                                           True if search == "" else None, 
                                           or_(*[Item.name.like('%{0}%'.format(s)) for s in words]), 
                                           or_(*[Item.code.like('%{0}%'.format(s)) for s in words]) 
                                            ))).order_by(Item.name)] 

还有这个。

if type == "code": 
            src = [Item.code.like('%{0}%'.format(s)) for s in words] 
        elif type == "name": 
            src = [Item.name.like('%{0}%'.format(s)) for s in words] 
 
 session.query(Item) 
                    .filter(and_( 
                        Item.companyId == company_id, 
                        Item.typeItem == item_type, 
                        or_( 
                            True if search == "" else None, 
                            or_(*src) 
                        ))) 

在这两种情况下,我在 or_() 语句中都有 * 运算符,并且这两个查询都非常有效,但我不知道确切原因。 这是reference和 this one