• 技术文章 >Python技术 >Python基础教程

    python序列操作的整理

    小妮浅浅小妮浅浅2021-06-07 16:22:04原创2690

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

    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电脑。

    专题推荐:python序列
    品易云
    上一篇:python dict.item()方法遍历字典 下一篇:python字符串中有哪些方法

    相关文章推荐

    • python mktime()如何计算时间• python数据模块类如何定义• python如何定义索引模块类• python搜索模块如何查询• python PyQt5如何实现窗口功能• python阻塞调度如何使用• python标记清除的过程• python单向链表如何实现• python双向链表的概念介绍• Python单向循环链表的创建• python有几种排序的方法• python顺序搜索的两种形式• python二分查找的原理• python哈希散列的映射• python中树有哪些种类• python装饰器如何保留原函数信息• python装饰器有哪些作用• python动态存取属性如何实现• python zip函数的使用注意

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网