python中字符串的使用
2015-07-21 16:29
585 查看
字符串的使用
1.
单引号与双引号在 python 中等效使用
a.
三引号('''或""")可用来写跨行的字符串,在其中,单、双引号均可使用。
b.
Python 中字符串"what's this"表示方式
方式 1:'what \'s this'. 这里用到了转义符'\'
方式 2:"what's this"
c.
行末的单独一个反斜杠表示字符串在下一行继续,而不是开始一个新的行:
"This is the first sentence.\
This is the second sentence."
等价于 "This is the first sentence. This is the second sentence."
d.
用 r 或 R 指定自然字符串
r"Happy\n", 一般’\n’代表回车,因为用'r'指定为自然字符串,因此'\n'不会被解释器理解
为回车换行符,而是'\'和'n'这两个字符,因此打印时会打印出"Happy\n"这 7 个字符。在
正则表达式中常用到。
e.
用 u 或 U 指定使用 unicode 编码. 如:u"Happy"
f.
连写的两个字符串会被解释器理解为一个连续的字符串
"what's"" your name"会被理解为"what's your name"
g. 字符串 strip(), find(), replace(), join(),split() 方法的掌握,后面有讲到
1.
单引号与双引号在 python 中等效使用
a.
三引号('''或""")可用来写跨行的字符串,在其中,单、双引号均可使用。
b.
Python 中字符串"what's this"表示方式
方式 1:'what \'s this'. 这里用到了转义符'\'
方式 2:"what's this"
c.
行末的单独一个反斜杠表示字符串在下一行继续,而不是开始一个新的行:
"This is the first sentence.\
This is the second sentence."
等价于 "This is the first sentence. This is the second sentence."
d.
用 r 或 R 指定自然字符串
r"Happy\n", 一般’\n’代表回车,因为用'r'指定为自然字符串,因此'\n'不会被解释器理解
为回车换行符,而是'\'和'n'这两个字符,因此打印时会打印出"Happy\n"这 7 个字符。在
正则表达式中常用到。
e.
用 u 或 U 指定使用 unicode 编码. 如:u"Happy"
f.
连写的两个字符串会被解释器理解为一个连续的字符串
"what's"" your name"会被理解为"what's your name"
g. 字符串 strip(), find(), replace(), join(),split() 方法的掌握,后面有讲到
相关文章推荐
- Python xlrd读取excel日期类型的2种方法
- python 多态实例
- python 多态实例
- 在Python的Django框架中显示对象子集的方法
- 关于python文件操作
- 再议使用Python批量裁切栅格
- 安装配置Python+Numpy+Scipy+Matplotlib环境
- python 安装 库
- python下导入自己定义的模块的方法
- [python] 发POST请求
- Python编辑器设置(包括Visual Studio Code和Sublime Text3)
- Python自省(反射)指南
- windows 下python安转numpy、opencv包
- Python开发者最常犯的10个错误
- Python之列表推导式List comprehensions例解
- 飘逸的python - inspect谁调用了我
- python实现查找文件名包含指定字符串的文件
- [python] 发GET请求
- python 中 高阶函数
- python sqlite3 插入数据例程