Lists and strings
A string is a sequence of characters and a list is a sequence of values, but a list of characters is not the same as a string. To convert from a string to a list of characters, you can use the list function:
list breaks a string into individual letters. If you want to break a string into words, you can use split method:
An optional argument called a delimiter specifies which characters to use as word boundaries. The following example uses ‘, ‘ ( a comma followed by a space) as the delimiter:
join is the inverse of split. It takes a list of strings and concatenates the elements. join is a string method, so you have to invoke it on the delimiter and pass the list as a parameter:
In this case, delimiter is a space character, so join puts a space between words. to concatenate strings without spaces, you can use the empty string, ‘’ as delimiter.
from Thinking in Python
最新文章
- nandflash驱动程序编写
- [zz] be similar with和be similar to的区别
- OpenCV学习笔记——多种Smooth平滑处理
- ios开发 json数据文件的存取
- get和post,session和cookie的一些说明
- SQVI和SAP查询QUERY的区别和使用注意事项
- match in shell scripts
- 设计社区Dribbble VS. Bēhance,你选谁?
- 团队作业6--展示博客(Alpha版本)
- SQL Server Service Broker创建单个数据库会话(消息队列)
- Java开发笔记(二十二)神奇的冒号
- DDoS的类型及原理
- Python 编程核心知识体系(REF)
- zepto 选中select option 的值
- C# MD5 加密,解密
- 高性能网络编程7--tcp连接的内存使用
- ASP.NET WebAPI Bearer Authorization
- mac rsync文件传输
- c语言for循环等语句详解
- ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]