Python - 字符串(string) 详解 及 代码
2013-12-04 10:11
597 查看
字符串(string) 详解 及 代码
本文地址: http://blog.csdn.net/caroline_wendy/article/details/17113225Python的字符串可以使用单引号('), 双引号("), 三引号('''); 三引号(''')里面, 可以添加单引号和双引号, 也可以通过转义序列(\)添加;
字符串放在一起自动连接成为一个字符串;
字符串前面添加限定词R或r, 表示是自然字符串(nature string), 可以忽略里面的格式限制;
在物理行末尾添加"\", 可以连接下一个物理行; 括号, 方括号, 大括号也可以一定限度的扩充物理行;
具体参见代码注释;
代码如下:
# -*- coding: utf-8 -*- #==================== #File: abop.py #Author: Wendy #Date: 2013-12-03 #==================== #eclipse pydev, python3.3 #三引号可以自由的使用双引号("")和单引号('') s = ''' I am a girl and like heels. Hello, "python" sister. ''' #转义序列"\" st = '''Hello, girls, l like (\'''). ''' #字符串放在一起自动连接 sa = 'Girls are ''the best. ' #r表示自然字符串, 不会进行转义(\n) sr = r"nature is good. \n {0}" #"\"表示连接字符串 sc = 'Oh, the lines are too \ large' #括号, 方括号, 大括号, 可以限定范围, 不用使用转义 print("the braces can do {thing}.". format(thing="lady")) print(s) print(st) print(sa) print(sr) print(sc)
输出:
the braces can do lady. I am a girl and like heels. Hello, "python" sister. Hello, girls, l like ('''). Girls are the best. nature is good. \n {0} Oh, the lines are too large
本文出自 “永不言弃” 博客,请务必保留此出处http://spikeking.blog.51cto.com/5252771/1387975
相关文章推荐
- Python - 字符串(string) 详解 及 代码
- python 字符串(string) format介绍和代码
- Python 基础之字符串string详解及实例
- python 字符串(string) format介绍和代码
- Python字符串操作和string模块代码分析
- Python - 翻转(reverse)字符串(string)的所有方法 详解
- python字符串string的内置方法实例详解
- Python操作redis字符串(String)详解 (三)
- Python字符串操作和string模块代码分析
- Python - 格式化(format())输出字符串 详解 及 代码
- Java String字符串最常见方法速查手册+代码示例详解
- Python - 格式化(format())输出字符串 详解 及 代码
- python字符串操作和string模块代码分析
- Python - 格式化(format())输出字符串 详解 及 代码
- python开发之字符串string操作方法实例详解
- 详解python 字符串和日期之间转换 StringAndDate
- python开发之字符串string操作方法实例详解
- Javascript类型系统之String字符串类型详解
- python 单行注释/多行注释/代码间注释/特殊注释/"""doc String
- NSString / NSMutableString 字符串处理,常用代码 (实例)