在python中列表,元祖,集合间可以进行相互转化,
def main(): set1={'hello','good','banana','zoo','Python','hello'} print(len(set1)) x=sorted(set1) print(type(x)) print(x) list1=list(set1) print(list1) list2=[1,2,3,1,2,4] set2=set(list2) print(set2) tuple1=(1,1,2,3,4,4) list3=list(tuple1) print(list3) set3=set(tuple1) print(set3) if __name__ == '__main__': main() 结果: 5 <class 'list'> ['Python', 'banana', 'good', 'hello', 'zoo'] ['banana', 'hello', 'zoo', 'good', 'Python'] {1, 2, 3, 4} [1, 1, 2, 3, 4, 4] {1, 2, 3, 4}