美文网首页
python-day5

python-day5

作者: 男神的领带 | 来源:发表于2018-09-29 16:25 被阅读0次

     1.什么字符串

    ''   空串

    ""   空串

     2.r/R在字符串的最前面阻止转义

     3.获取单个字符: 字符串[下标]

    下标:0 ~ 长度-1 ; -1 ~ -长度

     'abc'[0]

     'abc'[3]  # IndexError: string index out of range

    4.获取部分字符(切片): 字符串[起始下标:结束下标], 字符串[起始下标:结束下标:步长]

    print('abc'[::-1]) 

     4.+, *, 比较

     +: 连接

     12 + 'abc'  # TypeError: unsupported operand type(s) for +: 'int' and 'str'

     *: 重复

     ==, !=

    'abc' == 'abc'

    print('abc' == 'acb')

     >,<

    比较字符编码大小# in, not in

     len(字符串)

     5.格式字符串

     %s  --> 字符串

     %d  --> 整数

     %f  --> 小数

    %.nf --> 限制小数位数的小数

     %c  --> 字符

    str1 = '我是:%s %c' % ('acb', '胡')

    print(str1)

     6.其他的方法

    相关文章

      网友评论

          本文标题:python-day5

          本文链接:https://www.haomeiwen.com/subject/oxlboftx.html