python序列操作的整理
字符串也是一种序列类型。
1、转义字符:在某些字符之前添加\,可以表达特殊的含义,例如:\t代表缩进。
>>>string='Hello\nMy\tfriend' >>>print(string) #Hello #Myfriend
2、原始字符串:在引号前添加r,表示不转义字符串的内容。
>>>string=r'Hello\nMy\tfriend' >>>print(string) #Hello\nMy\tfriend
3、长字符串:用三个引号代替普通引号,表示保留文本的原始格式,适用于长段。
>>>string='''Toseeaworldinagrainofsand, Andaheaveninawildflower, Holdinfinityinthepalmofyourhand, Andeternityinanhour.''' >>>print(string) #Toseeaworldinagrainofsand, #Andaheaveninawildflower, #Holdinfinityinthepalmofyourhand, #Andeternityinanhour.
以上就是python序列操作的整理,希望对大家有所帮助。更多python学习指路:python基础教程
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。