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 requests库中的代理实例讲解

直接上代码: #request代理(proxy) """ 1.启动代理服务器Heroku,相当于aliyun 2.在主机1080端口启动Socks 服务 3.将请求转发到1080端口...

Python Django 命名空间模式的实现

Python Django 命名空间模式的实现

新建一个项目 app02 在 app02/ 下创建 urls.py: from django.conf.urls import url from app02 import view...

Python numpy数组转置与轴变换

Python numpy数组转置与轴变换

这篇文章主要介绍了Python numpy数组转置与轴变换,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 矩阵的转置 >&...

python购物车程序简单代码

python购物车程序简单代码

本文实例为大家分享了python购物车程序的具体代码,供大家参考,具体内容如下 代码: ''''' Created on 2017年9月4日 @author: len ''...

Python 的类、继承和多态详解

类的定义 假如要定义一个类 Point,表示二维的坐标点: # point.py class Point: def __init__(self, x=0, y=0): s...