python中list、tuple、set、dict区别

list、tuple、set、dict区别

参考:python的列表,字典,元组,集合的区别和各自使用方法

遍历set

由于set也是一个集合,所以,遍历set和遍历list类似,都可以通过for循环实现
直接用for循环遍历set中的元素

weekdays = set(['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN'])
for d in weekdays:
    print (d)

猜你喜欢

转载自www.cnblogs.com/whiteBear/p/12751508.html