list1=[‘name‘,‘age‘,‘address‘] print(‘把列表list1转换为字符串:‘,str(list1))print(type(str(list1)) str=‘wuya name sex age‘ print (‘把字符串str转换为列表:‘,str.split(‘ ‘))print(‘类型为:‘,type(str.split(‘ ‘)) print (‘把列表list1转换为元组:‘,tuple(list1))print(‘类型为:‘,type(tuple(list1)) tuple1=(‘android‘,‘ios‘,‘windows‘,‘firefoxos‘) print (‘把元组tuple1转换为列表:‘,list(tuple1))print(‘类型为:‘,type(list(tuple1)) dict1={‘name‘:‘wuya‘,‘age‘:18,‘address‘:‘xian‘} print (‘把字典dict1转换为列表:‘,list(dict1.items())print(‘类型为:‘,list(dict1.items())[(‘name‘, ‘wuya‘), (‘age‘, 18), (‘address‘, ‘xian‘)]
dict1={‘name‘:‘wuya‘,‘age‘:18,‘address‘:‘xian‘} print (‘把字典dict1转换为tuple:‘,tuple(dict1.items())print(‘类型为:‘,tuple(dict1.items())((‘name‘, ‘wuya‘), (‘age‘, 18), (‘address‘, ‘xian‘))
list2=list(dict1.items()) print (‘把列表转换为字典:‘,dict(list2))print(‘类型为:‘,type(dict(list2)){‘name‘: ‘wuya‘, ‘age‘: 18, ‘address‘: ‘xian‘}
tuple2=tuple(dict1.items()) print (‘把tuple转换为字典:‘,dict(typle2))print(‘类型为:‘,type(dict(tuple2)){‘name‘: ‘wuya‘, ‘age‘: 18, ‘address‘: ‘xian‘}
print (‘把列表list1转换为字典:‘,dict(enumerate(list1))print(‘类型为:‘,dict(enumerate(list1)){0: ‘ooo‘, 1: ‘uuu‘, 2: ‘tttt‘}
原文地址:https://www.cnblogs.com/fkkk/p/9914377.html
时间: 2024-11-13 08:06:53