组合数据类型综合练习:英文词频统计
字符串:
str="This is python!"
for i in str:
print(i)
列表:
str= ['ok','hi',[1997,1,1]]
for i in str:
print(i)
元组:
str2 = ('ok','hi',[1997,1,1])
for i in str2:
print(i)
集合:
str4 = [2,2,3,4,4,5,6,7]
str4 = set(str4)
for i in str4:
print(i)
列表,元组,字典,集合的联系与区别:
列表是用[]括起来,元组是用()括起来的,字典集合都是用{}括起来。
列表是可变序列,可以索引查找元素进行增删,而元组是只读列表,数据不可修改。
字典由一对对键值对组成,键唯一值不唯一,集合是由无序且不重复的数据组成。