Python‎ > ‎str‎ > ‎

str.endswith()

http://www.adilwaseem.com/

Definition
Return with True or False weather string ends with character nor not.

Syntax
str.endswith(x)-> True or False

Parameters
x=string

Examples
The function endswith() test the end of string to statement.
 >>> a="Python Lake"
>>> a.endswith("Lake")
True
>>> "Python Lake".endswith("e")
True
>>> str.endswith("Python Lake","e")
True
>>>

The method is used in if statement.
 x="122cc"
if x.endswith("c"):
print("yes, you're right")
else:
print("It is not numeric")
>>> 
yes, you're right
>>> 

If statement return with:
name1="Pythonlake"
if name1.endswith("e"):
print("Name character end with 'e'")
else:
print("No, ending character is different")
>>> 
Name character end with 'e'

Comments