python list 与 String 互相转换
str0 = '127.0.0.1'
list0 = str0.split('.')
print(list0)
#['127', '0', '0', '1']
str1 = '#'.join(list0)
12 #127#0#0#1
1、list转str
假设有一个名为test_list的list,转换后的str名为test_str
则转换方法:
test_str = "".join(test_list)
例子:

需要注意的是该方法需要list中的元素为字符型,若是整型,则需要先转换为字符型后再转为str类型。

2、str转list
假设有一个名为test_str的str,转换后的list名为test_list
则转换方法:
test_list=list(test_str)
例子:

3、生成连续数字list
print(list(range(1,33)))
print(range(1,33))
'''
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
range(1, 33)
'''
python list 与 String 互相转换的更多相关文章
- Python int与string 的转换
string → int 1.10进制的string转化为int int('12') → type(int('12')) 进行验证 2.16进制的string转化为int int('12', 16) ...
- 【python】bytearray和string之间转换,用在需要处理二进制文件和数据流上
最近在用python搞串口工具,串口的数据流基本读写都要靠bytearray,而我们从pyqt的串口得到的数据都是string格式,那么我们就必须考虑到如何对这两种数据进行转换了,才能正确的对数据收发 ...
- python基础===Character string
本文转自:python之Character string 1.python字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号('或")来创建字符串,l Python不支持单 ...
- Python中字符串String的基本内置函数与过滤字符模块函数的基本用法
Python中字符串String的基本内置函数与用法 首先我们要明白在python中当字符编码为:UTF-8时,中文在字符串中的占位为3个字节,其余字符为一个字节 下面就直接介绍几种python中字符 ...
- 编写Python脚本把sqlAlchemy对象转换成dict的教程
编写Python脚本把sqlAlchemy对象转换成dict的教程 在用sqlAlchemy写web应用的时候,经常会用json进行通信,跟json最接近的对象就是dict,有时候操作dict也会比操 ...
- python补充之进制转换、exec、eval、compile
目录 eval.exec和compile 1.eval函数 2.exec函数 eval()函数和exec()函数的区别 python中的进制转换 eval.exec和compile 1.eval函数 ...
- python unicode和string byte
python unicode 和string那 开发过程中总是会碰到string, unicode, ASCII, 中文字符等编码的问题, 每次碰到都要现搜, 很是浪费时间, 于是这次狠下心, 一定要 ...
- C# Byte[] 转String 无损转换
C# Byte[] 转String 无损转换 转载请注明出处 http://www.cnblogs.com/Huerye/ /// <summary> /// string 转成byte[ ...
- C# 之 将string数组转换到int数组并获取最大最小值
1.string 数组转换到 int 数组 " }; int[] output = Array.ConvertAll<string, int>(input, delegate(s ...
随机推荐
- Rust 1.31正式发布,首次引入Rust 2018新功能
Rust 1.31是第一个实现了Rust 2018独有新功能并且不保证与现有代码库兼容的版本.Rust 2018相关工作正在进行中,而Rust 1.31只是整个三年开发周期的开始,这个开发周期将对这门 ...
- Shiro(二):Spring-boot如何集成Shiro(上)
这篇文章主要介绍了spring-boot是如何集成shiro的authentication流程的. 从shiro-spring-boot-web-starter说起 shiro-spring-boot ...
- Codeforces Round #530 (Div. 1) 1098A Sum in the tree
A. Sum in the tree Mitya has a rooted tree with nn vertices indexed from 11 to nn, where the root ha ...
- The Preliminary Contest for ICPC Asia Xuzhou 2019 徐州网络赛 K题 center
You are given a point set with nn points on the 2D-plane, your task is to find the smallest number o ...
- String-StringBuilder-StringBuffer 的区别
String StringBuilder StringBuffer 的区别 String:不可改变的字符串,不能够被修改 (https://baijiahao.b ...
- muduo网络库源码学习————原子性操作Atomic.h
原子性操作可以做到比互斥锁更小的开销,在多线程编程中原子性操作是非常有用的.Atomic.h文件位于muduo/base下,代码如下: // Use of this source code is go ...
- sqlserver2005定期备份和清除
1.打开管理->维护计划 2.右键点击新建维护计划 3.给新的维护计划自定义命名 4.可以看左下角的维护方式 5.拖动“备份数据库”到右边 6.选中,编辑备份方式 7.选择备份方式,所有数据库, ...
- Datasource Server returns invalid timezone问题
今天在学习一个项目的时候,idea中的datasource没有配置,后来发现mysql没有连接,于是下载了最新版的jdbc.jar包,连接mysql完成后,想test一下mysql connect,结 ...
- B - Dining POJ - 3281 网络流
Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will c ...
- Java for 嵌套循环
嵌套循环 可以是for循环 while循环也可以是do-while循环 这三着进行组合嵌套 循环思路:先执行外层循环,内层循环作为外层循环的循环体,直到内层循环执行完毕,再次计算外层循环,根据条件决 ...