组合数据类型

组合数据类型练习:

分别定义字符串,列表,元组,字典,集合,并进行遍历。

字符串,并进行遍历。:

str = 'china'
for i in str:
    print(i)

列表,并进行遍历。:

a= ['a','b','c','d','e','f']
for i in a:
    print(i)

元组,并进行遍历。:

tu= ('physics', 'chemistry', 1997, 2000);
for i in range(len(tu)):
    print(tu[i])

字典,并进行遍历:

d = {'a':1,'b':2,'c':3,'h':4}

for k,v in d.items():
    print(k,v)

集合,并进行遍历:

st = set([1,2,'a','c',4,'d'])
for i in st :
    print(i)
原文地址:https://www.cnblogs.com/sunset-Panda/p/8626950.html