Function: EndsWith ()
Function: To determine whether a string ends with a specified character or substring, often used to determine file types
Correlation function: Judgment string opening startswith ()
I. Description of the function
syntax: String.endswith (str, Beg=[0,end=len (String))
String[beg:end].endswith (str)
Parameter description:
String: Detected strings
STR: The specified character or substring (you can use tuples to match each)
Beg: Sets the starting position for string detection (optional, from left)
End: Sets the ending position of the string detection (optional, from left)
If the parameter beg and end are present, they are checked in the specified range, otherwise the entire string is checked
return value:
Returns True if a string is detected, otherwise returns false.
Parsing: Returns True if string strings end with STR, otherwise returns false
Note: The null character is considered to be true
Second, the example
>>> s = ' Hello good boy doiido '
>>> print s.endswith (' o ')
True
>>> Print S.endswith (' ido ')
true
>>> print s.endswith (' Do ', 4)
true
>>> print S.endswith (' Do ', 4,15)
False
#匹配空字符集
>>> Print S.endswith (')
True
#匹配元组
>>> print s.endswith (' t ', ' B ', ' O '))
True
Common environment: Used to determine file types (such as pictures, executables)
>>> f = ' pic.jpg '
>>> if F.endswith ('. gif ', '. jpg ', '. png ')):
print '%s is a pic '%f
else:
print '%s is not a pic '%f
pic.jpg is a pic