Python字符串endswith()方法 |
您所在的位置:网站首页 › Python中endswith › Python字符串endswith()方法 |
Python字符串endswith()方法判断字符串以指定的子字符串为后缀(结尾),如果是则返回True,否则返回False,可选地限制由给定范围索引start和end来匹配。 语法 以下是endswith()方法的语法 - str.endswith(suffix[, start[, end]])参数 suffix - 这可以是将要查询的一个字符串或者也可以是一个后缀的元组。start - 从这里开始的切片位置。end - 从这里结束的切片位置。返回值 如果字符串以指定的后缀结束,则为TRUE,否则为FALSE。示例 以下示例显示了endswith()方法的用法。 #! /usr/bin/env python #coding=utf-8 # save file: logical_operators_example.py str='Welcome to yiibai python toturitals!' suffix='s!' print (str.endswith(suffix)) print (str.endswith(suffix,20)) suffix='python' print (str.endswith(suffix)) print (str.endswith(suffix, 0, len('Welcome to yiibai python')))当运行上面的程序,它产生以下结果 - True True False True上一篇: Python字符串 下一篇: Python列表 |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |