python-str,list,set间的转换实例

yipeiwu_com6年前Python基础

实例如下:

a = '123abbcc!@#' 
b = ['1', '2', '3', 'a', 'b', 'c', '!', '@', '#']
c = set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2']) 

str -> list:list(a) 
result : ['1', '2', '3', 'a', 'b','b', 'c','c','!', '@', '#']
list -> str : ''.join(list) 
result : 123abc!@#

str -> set : set(a)
result : set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2']) set类型是无序不重复的
set -> str :  ''.join(c) 
result: a!cb@#132

set -> list : list(c)
result : ['a', '!', 'c', 'b', '@', '#', '1', '3', '2']
list -> set : set(b)
result : set(['a', '!', 'c', 'b', '@', '#', '1', '3', '2'])

以上这篇python-str,list,set间的转换实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

Python获取基金网站网页内容、使用BeautifulSoup库分析html操作示例

本文实例讲述了Python获取基金网站网页内容、使用BeautifulSoup库分析html操作。分享给大家供大家参考,具体如下: 利用 urllib包 获取网页内容 #引入包 fr...

python根据出生日期返回年龄的方法

本文实例讲述了python根据出生日期返回年龄的方法。分享给大家供大家参考。具体实现方法如下: def CalculateAge(self, Date): '''Calcul...

Python3数字求和的实例

以下实例为通过用户输入两个数字,并计算两个数字之和: # -*- coding: UTF-8 -*- # Filename : test.py # author by : www...

python 生成器协程运算实例

一、yield运行方式 我们定义一个如下的生成器: def put_on(name): print("Hi {}, 货物来了,准备搬到仓库!".format(name)) wh...

pyqt5 键盘监听按下enter 就登陆的实例

记得导入包,其他按键可类比 def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Enter:...