zoukankan      html  css  js  c++  java
  • Python字符串运算符

    Python字符串运算符:

      + :连接左右两端的字符串。

      *  :重复输出字符串。

      [ ] :通过索引获取字符串中的值。

      [start:stop:step]:开始,结束位置的后一个位置,步长。

      in  :判断左端的字符是否在右面的序列中。

      not in:判断左端的字符是否不在右面的序列中。

      r/R :在字符串开头使用,使转义字符失效。

    # 字符串使用 + 号
    strs = "hello " + "world."
    print(strs)
    # hello world.
    
    # 字符串使用 * 号
    strs = 'abc '
    # 无论数字在哪一端都可以
    print(3*strs)
    # abc abc abc
    
    print(strs * 3)
    # abc abc abc
    
    # 使用索引下标
    strs = "hello world."
    print(strs[4])
    # o
    print(strs[7])
    # o
    
    # 切片操作,左闭右开原则
    strs = "hello world."
    # 将字符串倒序输出
    print(strs[::-1])
    # .dlrow olleh
    
    print(strs[6:11:])
    # world
    
    strs = "ABCDEFG"
    print("D" in strs)
    # True
    print("L" in strs)
    # False
    
    print("D" not in strs)
    # False
    print("L" not in strs)
    # True
    
    # 使用 r 使字符串中的转义字符失效
    print('a	b')
    # a    b
    print(r'a	b')
    # a	b

    2020-02-08

  • 相关阅读:
    Tips:数据的单位
    PHP面向对象三大特性③
    PHP面向对象三大特性②
    PHP面向对象三大特性①
    PHP-初识面向对象
    C# 基础·算法篇
    C# 基础·常见面试
    C# 特殊处理使用方法
    C# 第三方组件使用
    JS 插件使用
  • 原文地址:https://www.cnblogs.com/hany-postq473111315/p/12275891.html
Copyright © 2011-2022 走看看