分别定义字符串,列表,元组,字典,集合,并进行遍历。
# 字符串 sen = 'this' print(type(sen)) print(sen) # 数组 list1 = ['wher', 'is', 'you', 'cat', '?'] for i in list1: print(i) print(len(list1)) print(type(list1)) # 元组 tu = tuple(list1) print(tu) print(type(tu)) for u in tu: print(u) print(tu[2]) # 字典 di = {'a': 10, 'b': 20, 'c': 30} print(di['hhh']) # print(di) for key in di: print((str(key) + ':' + str(di[key]))) # 集合 s = set([4, 3, 9, 9, 6, 6, 6]) #重复元素会被自动过滤 print(s) s.add("a") print(s) for ss in s: print(ss)