The endswith Method in Python: Checking String Endings

Returns True or False indicating if a string ends with a specified suffix.

endswith(suffix[, start[, end]])

  • suffix: suffix string to check for
  • start: index to start the search from; supports negative values
  • end: index to end the search at; supports negative values
my_str = 'Disco world'
my_str.endswith('jockey')  # False
my_str.endswith('world')  # True
my_str.endswith('jockey', 2)  # False
my_str.endswith('Disc', 0, 4)  # True