Python 基础之字符串string详解及实例
2017-04-01 10:17
786 查看
Python字符串(string) 详解 及 代码
Python的字符串可以使用单引号('), 双引号("), 三引号('''); 三引号(''')里面, 可以添加单引号和双引号, 也可以通过转义序列(\)添加;
字符串放在一起自动连接成为一个字符串;
字符串前面添加限定词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
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣的文章:
- python开发之字符串string操作方法实例详解
- Python列表(list)、字典(dict)、字符串(string)基本操作小结
- Python原始字符串(raw strings)用法实例
- Python StringIO模块实现在内存缓冲区中读写数据
- python3中bytes和string之间的互相转换
- Python的string模块中的Template类字符串模板用法
- python中string模块各属性以及函数的用法介绍
- python实现字典(dict)和字符串(string)的相互转换方法
- Python 常用string函数详解
- Python中模块string.py详解
- Python编程之string相关操作实例详解
相关文章推荐
- python开发之字符串string操作方法实例详解
- python字符串string的内置方法实例详解
- python开发之字符串string操作方法实例详解
- Python基础知识(七)--字符串详解
- Python编程之string相关操作实例详解
- Python字符串处理实例详解
- Python基础-String字符串
- Python - 字符串(string) 详解 及 代码
- Python基础:数据类型-字符串:string
- Python基础之函数用法实例详解
- python基础知识(一)运算符-字符串详解
- python 查找字符串是否存在实例详解
- C++调用Python基础功能实例详解
- python基础学习——列表(list), 元祖(tuple), 字典(dict), 字符串(string), 集合(set) 介绍及相互转换
- Python 中开发pattern的string模板(template) 实例详解
- zlib库压缩和解压字符串STL string的实例详解
- String字符串对象基础详解
- 详解python 字符串和日期之间转换 StringAndDate
- Lua基础---lua字符串库函数详解,实例及正则表达式
- Java基础(极客)——14、Java String字符串详解