Python 中 list 没有 add 属性
为以下输入时,报错:
1>>> A = (['a', 'b', 'c', 'd'])
2>>> 'a' in A
3True
4>>> 'e' in A
5False
6>>> ABC = A.copy()
7>>> ABC.add('e')
8Traceback (most recent call last):
9 File "<stdin>", line 1, in <module>
10AttributeError: 'list' object has no attribute 'add'
11# no exit() 仍然报属性错误
12>>> abc = A.copy()
13>>> abc.add('e')
14Traceback (most recent call last):
15 File "<stdin>", line 1, in <module>
16AttributeError: 'list' object has no attribute 'add'
17>>>
报错输出为:list
对象没有 add
属性
为以下输入时,正常:
1>>> abc = set(['a', 'b', 'c', 'd'])
2>>> 'a' in abc
3True
4>>> 'e' in abc
5False
6>>> abcd = abc.copy()
7>>> abcd.add('e')
8>>> abcd.issuperset(abc)
9True
10>>> abc.remove('c')
11>>> abc & abcd # 或者是 abc.intersection(abcd)
12{'d', 'a', 'b'}
13>>>
有大小写字母的问题,并且还有其他的隐式问题。
待解决