• 技术文章 >Python技术 >Python基础教程

    python中的rfind函数如何使用

    FXLFXL2020-08-07 10:53:02原创5242
    python中rfind函数的用法:rfind()函数用于返回字符串最后一次出现的位置(从右向左查询),如果没有匹配项则返回“-1”。具体使用方法如:【print str.rfind(substr, 0, 10);】。

    函数描述:

    (推荐教程:Python入门教程

    Python rfind() 返回字符串最后一次出现的位置(从右向左查询),如果没有匹配项则返回-1。

    语法:

    str.rfind(str, beg=0 end=len(string))

    参数:

    举例:

    #!/usr/bin/python
    str = "this is really a string example....wow!!!";
    substr = "is";
    print str.rfind(substr);
    print str.rfind(substr, 0, 10);
    print str.rfind(substr, 10, 0);
    print str.find(substr);
    print str.find(substr, 0, 10);
    print str.find(substr, 10, 0);

    输出结果:

    5
    5
    -1
    2
    2
    -1
    专题推荐:python rfind
    品易云
    上一篇:怎么安装python3.7 下一篇:python launcher是什么

    相关文章推荐

    • 如何打开python控制台• python如何判断是否是一个目录• python中pop()函数怎么用

    全部评论我要评论

    © 2021 Python学习网 苏ICP备2021003149号-1

  • 取消发布评论
  • 

    Python学习网