How to Use String endswith() Method in PythonPython Basics


The endswith() method returns True if a string ends with the given suffix, otherwise False.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

str1 = "Jason Stanson is the most famous actor in Hollywood.!!!"
suffix = '!!!'
print(str1.endswith(suffix))

suffix = 'Hollywood'
print(str1.endswith(suffix))

Output:

True
False

Syntax

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

Parameters

Name Description
suffix String or tuple of suffixes to be checked.
start The starting position in the string.
end The end position in the character.

Return Value

It returns True or False.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us