Easy Tutorial
❮ Python Func Filter Ref Math Isclose ❯

Python3 endswith() Method

Python3 Strings


Description

The endswith() method is used to check if the string ends with the specified suffix. It returns True if the string ends with the specified suffix, otherwise it returns False. Optional parameters "start" and "end" specify the start and end positions for searching within the string.

Syntax

The syntax for the endswith() method is:

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

Parameters

Return Value

Returns True if the string contains the specified suffix, otherwise returns False.

Example

The following example demonstrates the endswith() method:

#!/usr/bin/python3

Str = 'tutorialpro example....wow!!!'
suffix = '!!'
print(Str.endswith(suffix))
print(Str.endswith(suffix, 20))
suffix = 'run'
print(Str.endswith(suffix))
print(Str.endswith(suffix, 0, 19))

The output of the above example is:

True
True
False
False

Python3 Strings

❮ Python Func Filter Ref Math Isclose ❯