热线电话:13121318867

登录
2018-11-09 阅读量: 850
字符串在Python里的操作

字符串可以用单引号或者双引号标注分隔出来(但引号需要配对,即单引号对单引号,双

引号对双引号):

single_quoted_string = 'data science'
double_quoted_string = "data science"
Python 用反斜线来为特殊字符编码。比如:
tab_string = "\t" # 表示tab字符
len(tab_string) # 1

如果你希望反斜线仅仅代表反斜线本身(你在 Windows 系统中的文件夹或者正则表达式中

也许会遇到), 那么可以使用命令 r"" 生成一个原始的字符串:

not_tab_string = r"\t" # 表示字符'\''t'

len(not_tab_string) # 2

你可以通过三重[两重]引号来生成多行的字符串:

multi_line_string = """This is the first line.
and this is the second line
and this is the third line"""
0.0000
4
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子