Python String类型基本应用情况分析

开发 后端
我们今天会通过对一段代码示例的解读来为大家详细介绍一下有关Python String类型的相关操作方法,大家可以从中获得更多的帮助。

Python String类型在实际应用中可以给我们带来非常大的好处。在接下来的文章中,我们将会在这里为大家详细介绍一下有关Python String类型的相关应用方式,希望大家可以充分的掌握这一应用。

Python String类型应用代码示例:

  1. >>> 'hello world'  
  2. 'hello world'  
  3. >>> "hello world"  
  4. 'hello world'  
  5. >>> "doesn't"  
  6. "doesn't"  
  7. >>> 'hello "tom"'  
  8. 'hello "tom"'  
  9. >>> "hello,\"tom\""  
  10. 'hello,"tom"'  
  11. >>> hello="hello,\  
  12. i miss you."  
  13. >>> print(hello)  
  14. hello,i miss you.  
  15. >>> print(r"hello\n world")  
  16. hello\n world  
  17. >>> word='hello'+'A'  
  18. >>> print(word)  
  19. helloA  
  20. >>> word[0:5]+'B'  
  21. 'helloB'  
  22. >>> word[-1]  
  23. 'A'  
  24. >>> len(word) 

注意:#t#

单引号''和双引号""作用相同,都用来表示字符串,但是单引号''中可以有双引号"",双引号""中也可以有单引号'',但是如果双引号""中使用双引号""或是单引号''中使用单引号''时,必须使用转义字符\,例如\'或\"。

行末尾\表示字符串换行。

字符串前的r表示纯字符串,此时字符串中的转义字符失效。

+表示字符串的链接。

[]可以用来索引字符串中的字符,但是不能用来修改字符串中的字符。

len()用来获得字符串的长度。

以上就是对Python String类型的相关介绍。

责任编辑:曹凯 来源: 博客园
相关推荐

2010-02-23 18:10:01

WCF绑定类型

2010-03-03 14:30:05

Python set类

2013-12-12 16:10:21

Lua脚本语言

2010-03-03 16:40:55

Python HTTP

2010-03-04 14:57:08

Python解密VBS

2010-03-01 18:11:40

WCF数据契约变更

2010-03-03 14:40:37

Python打包方法

2010-03-04 09:27:34

调用Python脚本

2010-03-03 10:03:55

Python连接Sql

2010-07-08 15:24:17

SNMP trap

2010-03-03 16:08:26

Python取得文件列

2017-11-30 18:42:22

PythonCPU脚本分析

2010-03-04 15:52:59

Python构造列表

2010-03-03 15:17:46

Python调用MyS

2010-02-04 17:16:33

C++调用python

2010-03-03 13:32:08

Python压缩文件

2010-02-25 10:52:29

WCF响应服务

2010-02-26 13:40:28

WCF消息头

2010-02-02 14:45:35

C++ typeof

2010-03-03 13:22:08

Python正则表达式
点赞
收藏

51CTO技术栈公众号