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 ...
随机推荐
- Redis数据迁移的三个方法
为什么80%的码农都做不了架构师?>>> 1. rdb数据备份恢复方法 redis 127.0.0.1:6379> SAVE OK 或者 redis-cli -h 127. ...
- 15个Nodejs应用场景
15个Nodejs应用场景 我们已经对Nodejs有了初步的了解,接下来看看Nodejs的应用场景. 2.1 Web开发:Express + EJS + Mongoose/MySQL express ...
- C#读写ini
using System; using System.IO; using System.Runtime.InteropServices; using System.Text; namespace ...
- 如何在linux服务器下快速安装配置Node.js
简单粗暴,先用xshell或其他软件连接服务器 1.下载(此处版本根据官网版本自己修改) wget https://npm.taobao.org/mirrors/node/v8.9.3/node-v8 ...
- Linux下创建 code diff 和 合并 patch
Linux 下经常需要给别人提供 patch 以及合 patch,这时需要用到 Linux 的 diff 和 patch 命令. 1. diff 命令 diff 命令常用来比较文件.目录,也可以用来制 ...
- NetCore项目实战篇02---全局异常处理
在 .netcore中可以自定义自己的异常类型,步骤如下: 1.自定义自己的异常类型UserOperationException 并继承自Exception public class UserOper ...
- Mybatis时间范围查询,亲测有效
Md2All export document .output_wrapper pre code{font-family: Consolas, Inconsolata, Courier, monospa ...
- 将A页面提交的数据id传递到B页面
A页面 在A页面跳转到B页面的时候,在url后面可以拼接参数 例如: window.location.href = './B.html?' + id; 跳转到B页面之后,可以通过url地址获取到从A页 ...
- RocketMQ搭建全过程
RocketMQ下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.3.0/rocketmq-all-4.3.0-bin-relea ...
- SQLite使用(一)
简单介绍SQLite常用API: int sqlite3_open( const char *filename, /* Database filename (UTF-8) */ sqlite3 **p ...