组合数据类型综合练习

字符串
str='Hello World Hi World'
print(str)
for i in str:
    print(i)

 列表

aaa = list('Hello World')
aaa.append(12345)
aaa.append(list('abc'))
print(aaa)
for i in aaa:
    print(i)
元组
abcd=tup1=('Hello World')
print(abcd)
for i in abcd:
    print(i)
字典
dict={'Ben',123,'Jack',456,'Tom',789}
print(dict)
for i in dict:
    print(i)
集合
ABC = list('helloworld')
QWE = set(ABC)
print(QWE)
for i in QWE:
    print(i)

  


总结列表,元组,字典,集合的联系与区别。
列表,元组,字典,集合中只有元组是可读的,二其他都是不可读的。列表,元组,字典,集合只有集合可以重复,其他都不可以重复。
列表和元组中存储的是值,而集合和字典存储的是键值对。列表和元组是有序的,集合是无序的,且字典是无序且自动正序的。
posted @ 2018-03-22 17:44  200张德标  阅读(102)  评论(0编辑  收藏  举报