字符串: 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)
列表是用[]括起来,元组是用()括起来的,字典集合都是用{}括起来
集合就是我们数学学的集合,没有什么特殊的定义。集合最好的应用是去重。集合没有特殊的表示方法,而是通过一个set函数转换成集合
集合与列表和元组不同,集合是无序的,也不能通过索引进行访问。此外,集合中的元素不能重复