python 字符串(str)和列表(list)的互相转换
1.str to list
str1 = "12345"
list1 = list(str1)
print list1
str2 = "123 sjhid dhi"
list2 = str2.split() #or list2 = str2.split(" ")
print list2
str3 = "www.google.com"
list3 = str3.split(".")
print list3
输出为:
['1', '2', '3', '4', '5']
['123', 'sjhid', 'dhi']
['www', 'google', 'com']
2. list to str
str4 = "".join(list3)
print str4
str5 = ".".join(list3)
print str5
str6 = " ".join(list3)
print str6
输出为:
wwwgooglecom
www.google.com
www google com
参考链接:
http://blog.csdn.net/cnmcsdn456/article/details/27830671
http://piziyin.blog.51cto.com/2391349/568426
https://blog.csdn.net/roytao2/article/details/53433373
python 字符串(str)和列表(list)的互相转换的更多相关文章
- Python字符串str的方法使用
#!usr/bin/env python# -*-coding:utf-8-*-#字符串通常用双引号或单引号来表示:'123',"abc","字符串"#str字 ...
- python 字符串方法及列表,元组,字典(一)
字符串 str 注: 若想要保持单引号和双引号为字符串的一部分 1)单双引号交替使用, 2)使用转义字符\ 3)成对三个引号被存在变量里 二.字符串详细用法 字符串的单个取值例 p_1=”hello” ...
- python字符串str
字符串str常用操作方法(都会产生新的数据) 1.取值: (1)索引:s[0] (2)切片:s[起始索引:结束索引:步长] 起始索引为0,可以省略 s最后一个索引可以取-1 结束索引省略,默认取到最后 ...
- Python字符串/元祖/列表/字典互转
#-*- coding:UTF-8 -*- #author:RXS002 #1.字典 dict = {'name':'Zara','age':7,'class':'First'} #字典转换为字符串, ...
- Python 字符串 (str)
作者博文地址:https://www.cnblogs.com/liu-shuai/ Python字符串的常用操作包括以下但不限于以下操作: 1 字符串的替换.删除.切片.复制.连接.比较.查找.分割等 ...
- python 字符串str和json格式转换
最近在写一个脚本,需要处理从excel中读取的数据,发现读取的json格式数据进行转换时报错 ValueError: Expecting property name enclosed in doubl ...
- day05 数据基本类型及内置方法:字符串str、列表list
一:可变不可变类型 1.可变类型 值改变,id不变,说明是直接改变原值,是可变类型 2.不可变类型 值改变,id也跟着改变,说明是产生了新的值,是不可变类型 二:数字类型 1.整型Int 用途: 记录 ...
- python字符串str和字节数组相互转化
b = b"Hello, world!" # bytes object s = "Hello, world!" # str object print('str ...
- python字符串str和字节数组bytes相互转化
1 引言 后续待补充 2 代码 b = b"Hello, world!" # bytes s = "Hello, world!" # string print( ...
- python字符串(str)
# value = "raitOrEi" # v = value.capitalize()#首字母大写 # print(v) # v1 = v.casefold()#全部变小写,不 ...
随机推荐
- Ubuntu12.04 root登陆方法【保证有效】
su -取得root权限后,gedit /etc/lightdm/lightdm.conf ,里面的内容全部改为 [SeatDefaults] greeter-session=unity-greete ...
- 阅读文章《DDD 领域驱动设计-如何 DDD?》的阅读笔记
文章链接: https://www.cnblogs.com/xishuai/p/how-to-implement-ddd.html 文章作者: 田园里的蟋蟀 首先感谢作者写出这么好的文章. 以下是我的 ...
- win10环境安装配置Nginx
前言: 参考 https://blog.csdn.net/kisscatforever/article/details/73129270 Nginx的应用场景 1. http服务器.Ngin ...
- C++ STL 之 vector
#include <iostream> #include <vector> using namespace std; void printVector(vector<in ...
- list 列表 函数的引用
方法 意义 L.index(v [, begin[, end]]) 返回对应元素的索引下标, begin为开始索引,end为结束索引,当 value 不存在时触发ValueError错误 L.inse ...
- Python学习记录7-继承
面向对象的三大特性 封装 继承 多态 封装 封装就是对对象的成员进行访问限制 封装的三个级别: 公开,public 受保护的,protected 私有的,private public,private, ...
- 【Day3】5.Python中的lxml模块
import lxml.etree as le with open('edu.html','r',encoding='utf-8') as f: html = f.read() html_x = le ...
- 阿里云MySQL用Navicat连接问题
阿里云上装好MySQL用Navicat连接出现密码正确,Navicat连接测试失败.解决方案:网上众多方案,比如:放行3306端口啥子的,加入安全组啥子的.确认这些都没问题,还是出现密码正确,测试连接 ...
- CSS基础学习 17.CSS动画
- Oracle中dual表的用途
dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情,如下: 1.查看当前用户,可以在 SQL Plus中执行下面语句 sele ...