python——列表&字符串互相转换方法小结
字符串(str)转列表(list)
转换方法:str.split()
str = 'zhu gao chao'
print(str.split(' ')) # 用split进行转换 str——>list 执行结果:
['zhu', 'gao', 'chao'] Process finished with exit code 0
列表(list)转字符串(str)
转换方法: str.join(list)
lis = ['zhu', 'gao', 'chao']
str = ''.join(lis) # 无缝拼接
print(str) #执行结果:
zhugaochao Process finished with exit code 0 lis = ['zhu', 'gao', 'chao']
str = ','.join(lis) # 用 , 拼接
print(str) #执行结果:
zhu,gao,chao Process finished with exit code 0
待更新……
python——列表&字符串互相转换方法小结的更多相关文章
- python 列表 字符串 转换
列表转字符串python中的列表l = ['1','2','3','4']转成str型'1,2,3,4'','.join(l)这个方法,列表里都是字符串的话可以这样用.列表里是整数的情况可以用: &g ...
- python中字符串编码方式小结
Python2中字符串的类型有两种:str和unicode,其中unicode是统一编码方式,它使得字符跟二进制是一一对应的,因此所有其他编码的encode都从unicode开始,而其他编码方式按照相 ...
- python列表字符串集合常用方法
1.1 列表常用方法 # 1. append 用于在列表末尾追加新的对象a = [1,2,3]a.append(4) # the result : [1,2,3,4]# 2. count方法统计某个 ...
- python 列表字符串元素乱序
from random import shuffle color = ['] shuffle(color) print(color)
- [转载] Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...
- Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
创建列表 sample_list = ['a',1,('a','b')] Python 列表操作 sample_list = ['a','b',0,1,3] 得到列表中的某一个值 value_star ...
- 转:Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
转自:http://blog.csdn.net/business122/article/details/7536991 创建列表 sample_list = ['a',1,('a','b')] Pyt ...
- Python列表、元组、字典和字符串的常用函数
Python列表.元组.字典和字符串的常用函数 一.列表方法 1.ls.extend(object) 向列表ls中插入object中的每个元素,object可以是字符串,元组和列表(字符串“abc”中 ...
- python列表和字符串的三种逆序遍历方式
python列表和字符串的三种逆序遍历方式 列表的逆序遍历 a = [1,3,6,8,9] print("通过下标逆序遍历1:") for i in a[::-1]: print( ...
随机推荐
- left与margin-left区别
left,right,top,bottom仅对于position:relative|absolute|fixed的元素有意义. <!DOCTYPE html PUBLIC "-//W3 ...
- 用Emit技术替代反射
之前在上篇博客说到用表达式来替代反射机制,可以获得较高的性能提升.这篇我们来说说用Emit技术来替代反射. System.Reflection.Emit命名空间类可用于动态发出Microsoft中间语 ...
- C# Soap调WebService
public class WebServiceHelper { /// <summary> /// Soap协议Post方法 /// </summary> /// <pa ...
- Windows环境下完全手工配置Apache、MySQL和PHP
现在LAMP(Linux.Apache.MySQL.PHP/Perl/Python的简称)已经很流行了.在Windows下也有类似的,比如 WAMP(Apache, MySQL, PHP on Win ...
- jquery ajax 脑图
- 使用maven结合requirejs管理前端脚本
已有的web项目,一直使用Maven做工程管理,现阶段前端调整为使用requirejs来负责模块加载依赖,同时使用jasmine来完成前端的UT. 便与在maven下统一管理,简单整理了下合在一起的使 ...
- 92. Reverse Linked List II【Medium】
92. Reverse Linked List II[Medium] Reverse a linked list from position m to n. Do it in-place and in ...
- python-class(4)
#!/usr/bin/env python #-*- coding:utf-8 -*- ############################ #File Name: class4.py #Auth ...
- 生产环境中 Ngx_lua 使用技巧和应用的范例
生产环境中 Ngx_lua 使用技巧和应用的范例 时间 -- :: 51CTO技术博客 原文 http://rfyiamcool.blog.51cto.com/1030776/1252501 主题 L ...
- c++ [wrong]simple "Garbage Collector"
In fact, Ptr alone can accomplish the task mentioned below. Implementation see Ptr.h, main2.cpp. In ...