第26823题 单选题
检查字符串括号匹配的Python代码中横线上应填写什么内容

以下代码用于检查字符串中的括号是否匹配,横线上应填写( )。

def is_balanced(s):
    stack = []
    for c in s:
        if c in '([{':
            stack.append(c)
        else:
            if not stack:
                return False
            top = stack.pop()

            if (c == ')' and top != '(') or \
                (c == ']' and top != '[') or \
                (c == '}' and top != '{'):
                return False
    __________________
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析