Python string endswith method

Is a string ending with a sub string

endswith allows us to find out if a string is ending with a substring. The syntax of endswith is as follows.

s.endswith(sub [, start [, end]]) It returns True if string s ends with substring sub. start and end give optional begin and end points for matching sub.


name = 'java2s.com'
if name.endswith('2s.com'): 
  print 'Hello, java2s.com' 
  

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary