从答题规范上,是不是用入栈出栈的思路应该这么写: def test_kuohao(s): # 函数名是随便起的 Q = [] sdict = {"(": ")", "[": "]", "{": "}",} try: for a in s: if len(Q) > 0 and sdict[Q[-1]] == a: Q.pop() # 出栈 else: Q.append(a) # 入栈 except: # 如果先遇到了右括...