Python string endswith() method example

In this source code example, we will demonstrate how to use the Python string endswith() method to check if a string ends with another string.

We use the Python string endswith() method to determine if a string ends with another string.

Python string endswith() method examples

The following example uses the string endswith() method to determine if a string ends with another string:

s = 'Source Code Examples'
result = s.endswith('Examples')
print(result)

Output:

True
The following example uses the endswith() method to check if a sentence ends with a fullstop (.), a question mark (?), or an exclamation mark (!):

marks = ('.', '?', '!')
sentence = 'Hello, how are you?'
result = sentence.endswith(marks)

print(result)

Output:

True

Related Python String Examples

  1. Python string literals
  2. Python string length example
  3. Python String join() method example
  4. Python string split() method example
  5. Python String index() method example
  6. Python string find() method example
  7. Python string startswith() method example
  8. Python string endswith() method example
  9. Python String lower() method example
  10. Python String upper() method example
  11. Python string title() method example
  12. Python string capitalize() method example
  13. Python string islower() method example
  14. Python string istitle() method example
  15. Python string isupper() method example
  16. Python string swapcase() method example
  17. Python string strip() method example
  18. Python string replace() method example
  19. Python string isdigit() method example
  20. Python string isdecimal() method example
  21. Python string isnumeric() method example
  22. Python string isalpha() method example
  23. Python string isalnum() method example


Comments