• Python字符串


    Python中字符串被定义为引号之间的字符集合。python支持使用成对的单引号双引号,三引号(三个连续的单引号或者双引号)可以用来包含特殊的字符。使用索引操作符([])和切片操作符可以得到子字符串

    第一个字符串索引是0,最后一个字符索引是-1.子字符串包含切片中的起始下标,但不包含结束下标

    加号用于字符串的连接,星号用于字符串重复

    >>> pystr = 'Python'
    >>> iscool = "is cool!"
    >>> pystr[0]
    'P'
    >>> pystr[2:5]
    'tho'
    >>> iscool[:2]
    'is'
    >>> iscool[3:]
    'cool!'
    >>> iscool[-1]
    '!'
    >>> pystr + iscool
    'Pythonis cool!'
    >>> pystr + '' + iscool
    'Pythonis cool!'
    >>> pystr + ' ' + iscool    #字符串的拼接
    'Python is cool!'
    >>> pystr*2          #字符串的重复操作
    'PythonPython'
    >>> '-' * 20
    '--------------------'
    >>> pystr = '''python 
    ... is cool!'''
    >>> pystr
    'python 
    is cool!'
    >>> print pystr
    python 
    is cool!

  • 相关阅读:
    python虚拟环境--virtualenv
    求导法则和高阶导数
    restful规范
    python协程--yield和yield from
    打印质数
    更改docker的存储位置
    同台ECS安装多个mysql
    jenkins + gitlab + harbor + k8s 部署项目
    jenkins 配置maven
    gitlab + jenkins 持续集成
  • 原文地址:https://www.cnblogs.com/weiwenbo/p/6552380.html
Copyright © 2020-2023  润新知