zoukankan      html  css  js  c++  java
  • python find函数

    Python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回-1

    find()函数语法:str.find(str, beg=0, end=len(string))

    参数
    str -- 指定检索的字符串
    beg -- 开始索引,默认为0。
    end -- 结束索引,默认为字符串的长度。

    返回值
    如果包含子字符串返回开始的索引值,否则返回-1。

    实例:

    #!/usr/bin/python

    str1 = "this is string example....wow!!!";
    str2 = "exam";

    print str1.find(str2); #15
    print str1.find(str2, 10);#15
    print str1.find(str2, 40);#-1

    注意:以下情况

    info = 'abca'

    if info.find('a'):

        print "yes"

    else:

        print "no"

    #返回 no,其实应该判断是否 == -1

    if info.find('f'):

      print "yes"

    else:

      print "no"

    #返回yes 

    以上两点需要注意。

  • 相关阅读:
    php内核为变量的值分配内存的几个宏
    php7 引用成为一种类型
    function参数
    execvp php-fpm reload使用的函数
    fastcgi
    php-fpm定时器
    php 类继承
    php 对象 调用静态方法
    php unset变量
    php5数组与php7数组区别
  • 原文地址:https://www.cnblogs.com/gide/p/5566077.html
Copyright © 2011-2022 走看看