python之函式用法endswith

2022-03-12 21:46:10 字數 904 閱讀 7256

#

-*- coding: utf-8 -*-

#python 27

#xiaodeng

#python之函式用法endswith()

##endswith()

#說明:返回布林值,判斷字串是否以指定字尾結尾.可選引數"start"與"end"為檢索字串的開始與結束位置

'''endswith(...)

s.endswith(suffix[, start[, end]]) -> bool

suffix:字串或乙個元素,就是需要查詢的字元或字串

start:字串的開始位置

end:字串結束位置

return true if s ends with the specified suffix, false otherwise.

with optional start, test s beginning at that position.

with optional end, stop comparing s at that position.

suffix can also be a tuple of strings to try.

'''#案例#

判斷字串是否以指定字尾結尾

str='

xiaodeng love python

'suffix='

python

'print str.endswith(suffix)#

true

suffix='is'

print str.endswith(suffix)#

false

suffix='

love

'print str.endswith(suffix,4,13)#

true

python之函式用法 setattr

coding utf 8 python 27 xiaodeng python之函式用法 setattr 用 setattr 函式重構方法 class fruit def init self,color,price self.color color self.price price def setat...

python之函式用法getattr

coding utf 8 python 27 xiaodeng python之函式用法getattr getattr 說明 getattr getattr object,name default value default 預設值 get a named attribute from an obje...

python之函式用法startswith

coding utf 8 python 27 xiaodeng python之函式用法startswith startswith 說明 返回布林值,用於檢查字串是否是以指定子字串開頭,如果是則返回 true,否則返回 false。startswith s.startswith prefix star...