组合数据类型综合练习:英文词频统计

1.组合数据类型练习:
分别定义字符串,列表,元组,字典,集合,并进行遍历。
总结列表,元组,字典,集合的联系与区别。

字符串:
str1 = "hello everyone"
for i in str1:
    print(i)
列表:
str2 = ['jay','male',[1996,12,2]]
for i in str2:
    print(i)
元组:
str3 = ('jay','male',[1996,12,2])
#str3 = tuple(str2)
for i in str3:
    print(i)
字典:
str4 = {
    'stu1':"Jay",
    'stu2':"Ran",
    'stu3':"Xi",
    'stu4':"Biao",
}
#str2 = ["stu1","stu2","stu3","stu4"]
#str3 = ["jay","ran","xi","biao"]
#str4 = dict(zip(str2,str3))
for i in str4:
    print(i)
集合:
str5 = [1,2,3,3,2,4,5,5,6]
str5 = set(str5)
for i in str5:
    print(i)

列表是用[]括起来,元组是用()括起来的,字典集合都是用{}括起来。
列表是可变序列,可以索引查找元素进行增删,而元组是只读列表,数据不可修改。

字典由一对对键值对组成,键唯一值不唯一,集合是由无序且不重复的数据组成。

原文地址:https://www.cnblogs.com/Ming-jay/p/8625796.html