您当前的位置:首页 > IT编程 > python
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 |

自学教程:Python endswith()方法

51自学网 2023-01-09 15:59:55
  python
这篇教程Python endswith()方法写得很实用,希望能帮到您。

描述

Python endswith() 方法用于判断字符串是否以指定后缀结尾,如果以指定后缀结尾返回True,否则返回False。可选参数"start"与"end"为检索字符串的开始与结束位置。

语法

endswith()方法语法:

str.endswith(suffix[, start[, end]])

参数

  • suffix -- 该参数可以是一个字符串或者是一个元素。
  • start -- 字符串中的开始位置。
  • end -- 字符中结束位置。

返回值

如果字符串含有指定的后缀返回True,否则返回False。

实例

以下实例展示了endswith()方法的实例:

实例(Python 2.0+)

#!/usr/bin/python str = "this is string example....wow!!!"; suffix = "wow!!!";print str.endswith(suffix);print str.endswith(suffix,20); suffix = "is";print str.endswith(suffix, 2, 4);print str.endswith(suffix, 2, 6);

以上实例输出结果如下:

TrueTrueTrueFalse

Python encode()方法
Python expandtabs()方法
51自学网自学EXCEL、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。
京ICP备13026421号-1