Skip to main content
 首页 » 编程设计

python之"or {}"是否像在 javascript 中一样在 python 中工作

2024年08月23日39birdshome

<分区>

这是我的第一个代码:

def __init__(self, attrs=None): 
    if not attrs: 
        attrs = {} 
    attrs['data-select2-json'] = "true" 

然后我在 JavaScript 中试了一下:

def __init__(self, attrs=None): 
    attrs = attrs or {} 
    attrs['data-select2-json'] = "true" 

它似乎有效,但我想知道:“或 {}”在 python 中是否像在 javascript 中一样工作? (很难用谷歌搜索这个!)它和我第一个代码的简单“if”一样快吗?