Python中處理字符串之endswith()方法的使用簡介
來源:懂視網
責編:小采
時間:2020-11-27 14:41:26
Python中處理字符串之endswith()方法的使用簡介
Python中處理字符串之endswith()方法的使用簡介:endswith()方法返回true,如果字符串以指定后綴結尾,否則返回(False可選限制的匹配從給定的索引開始和結束)。 語法 以下是endswith()方法的語法: str.endswith(suffix[, start[, end]]) 參數 suffix -- 這可能是一個字符串或者是
導讀Python中處理字符串之endswith()方法的使用簡介:endswith()方法返回true,如果字符串以指定后綴結尾,否則返回(False可選限制的匹配從給定的索引開始和結束)。 語法 以下是endswith()方法的語法: str.endswith(suffix[, start[, end]]) 參數 suffix -- 這可能是一個字符串或者是

endswith()方法返回true,如果字符串以指定后綴結尾,否則返回(False可選限制的匹配從給定的索引開始和結束)。
語法
以下是endswith()方法的語法:
str.endswith(suffix[, start[, end]])
參數
suffix -- 這可能是一個字符串或者是元組用于查找后綴。
start -- 切片從此開始
end -- 切片到此為止
返回值
如果字符串以指定的后綴結束此方法返回true,否則返回false。
例子
下面的例子顯示了endswith()方法的使用。
#!/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);
當我們運行上面的程序,它會產生以下結果:
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
Python中處理字符串之endswith()方法的使用簡介
Python中處理字符串之endswith()方法的使用簡介:endswith()方法返回true,如果字符串以指定后綴結尾,否則返回(False可選限制的匹配從給定的索引開始和結束)。 語法 以下是endswith()方法的語法: str.endswith(suffix[, start[, end]]) 參數 suffix -- 這可能是一個字符串或者是