Advertisement
endswith(value, start, end)
Parameters | Description |
---|---|
value | This is a string value, which is searched in the invoked string. A non-optional attribute. |
start | This is an integer value to specify the index position(zero-based index) to start the search at. An optional attribute. |
end | An integer value to specify the index position(one-based index) to end the search at. An optional attribute. |
# Python - Example of endswith() method.
# Creating a string
s1 = 'Hello World'
# Printing the value of string
print('String is : ', s1)
# Checking if the string ends with the value 'ld'
b1 = s1.endswith('ld')
print('Does ', s1 , ' ends with ld ? ', b1)
# Checking if the string ends with the value 'Hello'
b2 = s1.endswith('Hello')
print('Does ', s1 , ' ends with Hello ? ', b2)
# Checking if the string ends with the value 'World'
b3 = s1.endswith('World')
print('Does ', s1 , ' ends with World ? ', b3)
# Checking if the string ends with the value 'Wor'
b3 = s1.endswith('Wor')
print('Does ', s1 , ' ends with Wor ? ', b3)
String is : Hello World
Does Hello World ends with ld ? True
Does Hello World ends with Hello ? False
Does Hello World ends with World ? True
Does Hello World ends with Wor ? False
# Python - Example of endswith() method.
# Creating a string
s1 = 'World Peace'
# Printing the value of string
print('String is : ', s1)
# Checking if the string ends with the value 'World'
b1 = s1.endswith('eace')
print('Does ', s1 , ' ends with eace ? ' , b1)
# Checking if the string ends with the value 'world'
b2 = s1.endswith('peace')
print('Does ', s1 , ' ends with peace ? ', b2)
# Checking if the string ends with the value 'WORLD'
b3 = s1.endswith('PEACE')
print('Does ', s1 , ' ends with PEACE ? ', b3)
String is : World Peace
Does World Peace ends with eace ? True
Does World Peace ends with peace ? False
Does World Peace ends with PEACE? False
Advertisement
# Python - Example of endswith() method.
# Creating a string
s1 = 'The Sky'
# Checking if the string has a value ' Sky', starting at index 3 and ending at 6
# which is false because the value ' Sky' starts at index 3(zero-based index) but ends at index 7(one-based index)
b1 = s1.endswith(' Sky', 3, 6)
print(b1)
# Checking if the string has a value 'Sky', starting at index 4 and ending at 7
# which is true because the value 'Sky' starts at index 4 and ends at index 7
b1 = s1.endswith('Sky', 4, 7)
print(b1)
# Checking if the string has a value ' Sky', starting at index 3 and ending at 7
# which is true because the value ' Sky' starts at index 3 and ends at index 7
b1 = s1.endswith(' Sky', 3, 7)
print(b1)
# Checking if the string ends with the value 'ky', starting at index 5 and ending at 10
# which is true because the value 'ky' ends at the index 5 and ends before or at index 10
b2 = s1.endswith('ky', 5, 10)
print(b2)
# Checking if the string ends with the value 'y', starting at index 2 and ending at index 5
# which is false because the value 'y' does not start at index 2
b3 = s1.endswith('y', 2, 5)
print(b3)
False
True
True
True
False
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement