品易云推流 关闭
文章详情页
文章 > Python基础教程 > python序列操作的整理

python序列操作的整理

python序列

头像

小妮浅浅

2021-06-07 16:22:042984浏览 · 0收藏 · 0评论

字符串也是一种序列类型。

1、转义字符:在某些字符之前添加\,可以表达特殊的含义,例如:\t代表缩进。

>>> string = 'Hello\nMy\tfriend'
>>> print(string)
# Hello
# My friend

2、原始字符串:在引号前添加r,表示不转义字符串的内容。

>>> string = r'Hello\nMy\tfriend'
>>> print(string)
# Hello\nMy\tfriend

3、长字符串:用三个引号代替普通引号,表示保留文本的原始格式,适用于长段。

>>> string = '''To see a world in a grain of sand,
And a heaven in a wild flower,
Hold infinity in the palm of your hand,
And eternity in an hour.'''
>>> print(string)
# To see a world in a grain of sand,
# And a heaven in a wild flower,
# Hold infinity in the palm of your hand,
# And eternity in an hour.

以上就是python序列操作的整理,希望对大家有所帮助。更多Python学习指路:python基础教程

推荐操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

关注

关注公众号,随时随地在线学习

本教程部分素材来源于网络,版权问题联系站长!

底部广告图