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
  • 相关阅读:
    NOIP 模拟 $26; m 降雷皇$
    NOIP 模拟 $26; m 神炎皇$
    NOIP 模拟 $25; m queen$
    NOIP 模拟 $25; m string$
    创建自己的数字货币
    Etherscan
    ETH挖矿
    Claymore's Dua Miner挖矿教程
    微擎微赞密码重置
    SQL引擎及事务支持
  • 原文地址:https://www.cnblogs.com/st12345/p/8796810.html
Copyright © 2011-2022 走看看