zoukankan      html  css  js  c++  java
  • python字符串相关操作

    1、判断字符串是否以某个字符或者字符串开头:

    1 >>> c="as_as_ddd_Fge_f"
    2 >>> print c.startswith('f')
    3 False
    4 >>> print c.startswith('as')
    5 True
    6 >>> print c.startswith('a')
    7 True
    8 >>> print c.startswith('as_')
    9 True
    View Code

    2、判断字符串是否以某个字符或者字符串结束:

    1 >>> c="as_as_ddd_Fge_f"
    2 >>> print c.endswith('f')
    3 True
    4 >>> print c.endswith('fs')
    5 False
    6 >>> print c.endswith('_f')
    7 True
    View Code

    3、判断字符串中某个字符或者字符串出现的次数:

    1 >>> c="as_as_ddd_Fge_f"
    2 >>> print c.count('d')
    3 3
    4 >>> print c.count('_d')
    5 1
    6 >>> print c.count('_')
    7 4
    8 >>> print c.count('1')
    9 0
    View Code

    4、判断某个字符串、列表、是否含有某个字符或字符串:

     1 >>> c="as_as_ddd_Fge_f"
     2 >>> print "a" in c
     3 True
     4 >>> print "as" in c
     5 True
     6 >>> print "1" in c
     7 False
     8 >>> c=['q','b','2']
     9 >>> print "q" in c
    10 True
    11 >>> print "qq" in c
    12 False
    13 >>> print "3" in c
    14 False
    15 >>> print "2" in c
    16 True
    View Code
  • 相关阅读:
    GNU安装
    camera链接
    右键terminal
    Angular cli 常见问题
    Angular路由复用策略RouteReuseStrategy
    angular5 websocket 服务
    promise 极简版封装
    js a 标签 通过download 实现下载功能
    angular6 升级到 angular7+ 最新Ng-zorro
    最新IDEA永久激活
  • 原文地址:https://www.cnblogs.com/st12345/p/8796810.html
Copyright © 2011-2022 走看看