zoukankan      html  css  js  c++  java
  • 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!

  • 相关阅读:
    优化页面响应时间
    php性能优化
    加快compser install 和update的方法
    好用的类库
    php会话(session)实现原理
    mysql引擎
    数据库事物四大特性
    数据库索引
    insert和insertSelective区别
    java面试题之int和Integer的区别
  • 原文地址:https://www.cnblogs.com/weiwenbo/p/6552380.html
Copyright © 2011-2022 走看看