组合数据类型综合练习
字符串联系:
t1=['ab','bc','cd'] for i in t1: print(i)
结果:
列表:
lis = list(t1) lis.append(list('132456')) for i in lis: print(i)
结果:
元组:
tur = ('uu', 'ee', 'eee') tur ('uu', 'ee', 'eee') for i in tur: print(i)
结果:
字典:
classmates = ['Michael', 'Bob', 'Tracy','Boc' ,'Tracy']
score=[90,100,80,88,99]
d=dict(zip(classmates ,score))
d1 = dict(zip('cvb', 'wer'))
dict={'a'}
dict1={}
dit = {}
dit['nacy'] = 90
dit['jacky'] = 99
dit
{'nacy': 90, 'jacky': 99}
dit.items()
dict_items([('nacy', 90), ('jacky', 99)])
dit.keys()
dict_keys(['nacy', 'jacky'])
for i in dit:
print(i)
print(d)
print(d['Tracy'])
print(d1)
print(dict,dict1)
结果:
集合:
con = {'a', 'b', 'c'} con.add('v') {'c', 'b', 'a', 'v'} # con = set('boy') print(con)
con = {'a', 'b', 'c','c'}
con_set = set(con)
print(con)
结果: