python学习string method: find and rfind
来源:互联网 发布:对于java的理解 编辑:程序博客网 时间:2024/05/17 19:21
python 自带的两个查找字符串的方法:find 和rfind.
Python String find() Method
Description:
This method determines if
Syntax:
str.find(str, beg=0 end=len(string))
Parameters:
Here is the detail of parameters:
str: specifies the string to be searched.
start
: starting index, by default its 0 end
: ending index, by default its equal to the lenght of the string.
Return Value:
It returns index if found and -1 otherwise.输出的index从0开始,和list是一致的,index都是从0开始
Example:
#!/usr/bin/python str1 = "this is string example....wow!!!"; str2 = "exam"; print str1.find(str2); print str1.find(str2, 10); print str1.find(str2, 40);
This will produce following result:
15 15 -1
find 是从左起始查找,对应的从右开始查找的方法是rfind() Method
Description:
This method returns the last index where the substring
Syntax:
str.rfind(str, beg=0 end=len(string))
Parameters:
Here is the detail of parameters:
str: specifies the string to be searched.
start
: starting index, by default its 0 end
: ending index, by default its equal to the lenght of the string.
Return Value:
It returns last index if found and -1 otherwise.
Example:
#!/usr/bin/python str = "this is really a string example....wow!!!"; str = "is"; print str.rfind(str); print str.rfind(str, 0, 10); print str.rfind(str, 10, 0); print str.find(str); print str.find(str, 0, 10); print str.find(str, 10, 0);
This will produce following result:
5 5 -1 2 2 -1
- python学习string method: find and rfind
- python find rfind
- Python String find() Method
- C++ string中find() ,rfind() 函数
- python find() 与 rfind()的区别
- string::rfind
- string::rfind
- string类库中的find和rfind函数
- str.find() & str.rfind()
- c++ string::rfind注释
- c++ string之rfind
- C++ string中find() ,rfind() 等函数 用法总结及示例
- C++ string中find() ,rfind() 等函数 用法总结及示例
- C++ string中find() ,rfind() 等函数 用法总结及示例
- C++基础---string类的find/find_first_of/find_first_not_of/rfind/find_last_of/find_last_not_of
- C++ string中find() ,rfind() 等函数 用法总结及示例
- Python String translate() Method
- Python String Method
- const的用法 较详细
- 设计模式三:原型模式
- AlertDialog添加控件 .
- 蛋痛的 open in another editor 错误问题
- 按钮事件弹出多个AlertDialog,如何处理?
- python学习string method: find and rfind
- hdu 1569 方格取数(2)
- Printf and Printk
- SQL 模糊查询
- 那些争议最大的编程观点
- Parcelable 应用举例
- 发改委:三家电商正自查整改 厂商退出京东
- 40%的移动广告点击都是没价值的
- 内部排序算法c语言简单实现实现