字典
dict= {'语文': 89, '数学': 92, '英语': 93}
print(dict)
{'语文': 89, '数学': 92, '英语': 93}
dict = {}
print(dict)
{}
dict2 = {(20, 30):'good', 30:'bad'}
print(dict2)
{(20, 30): 'good', 30: 'bad'}
scores = {'语文': 89}
print(scores['语文'])
89
增加
scores['数学'] = 93
scores[92] = 5.7
print(scores)
{'语文': 89, '数学': 93, 92: 5.7}
删除
del scores['语文']
del scores['数学']
print(scores)
{92: 5.7}
修改
dict={'语文':89,'数学':93,'英语':100}
dict['语文']=100
print(dict)
{'语文': 100, '数学': 93, '英语': 100}
查找
scores = {'语文': 89}
print(scores['语文'])
89
元组
t1 = ([1,2,3],4)
print(t1)
([1, 2, 3], 4)
增加
t1 = ([1,2,3],4)
t1[0].append(4)
print(t1)
([1, 2, 3, 4], 4)
删除
t2=(1,2,3,4)
del t2
查找
t2=(1,2,3,4)
print(t2[1])
2
集合
a={1,2,3,4,5}
print(a)
{1, 2, 3, 4, 5}
增加
a.add(6)
print(a)
{1, 2, 3, 4, 5, 6}
a.update([7,9])
print(a)
{1, 2, 3, 4, 5, 6, 7, 9}
删除
a.pop()
print(a)
{2, 3, 4, 5, 6, 7, 9}
a.remove(2)
print(a)
{3, 4, 5, 6, 7, 9}