教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 python中的rfind函数如何使用

python中的rfind函数如何使用

发布时间:2021-02-12   编辑:jiaochengji.com
教程集为您提供python中的rfind函数如何使用等资源,欢迎您收藏本站,我们将为您提供最新的python中的rfind函数如何使用资源

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

函数描述:

(推荐教程:Python入门教程)

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

语法:

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

参数:

  • str -- 查找的字符串

  • beg -- 开始查找的位置,默认为 0

  • end -- 结束查找位置,默认为字符串的长度。

举例:

#!/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函数如何使用
python如何查看类的函数
python 怎么改文件名
Python dir()和help()帮助函数
Python find()方法:检测字符串中是否包含某子串
Python字符串大小写转换的函数及用法
python是否支持函数重载
python如何调用函数库
python如何调用函数中的数组
python中如何调用写文件函数

[关闭]
~ ~