Be sure to like, share and comment to show your support for our tutorials.
=======================================
Channel - https://goo.gl/pnKLqE
Playlist For This Tutorial - https://goo.gl/EyZFti
Latest Video - https://goo.gl/atWRkF
Facebook - / mastercodeonline
Twitter - https://twitter.com/mastercodeonlin?l...
Website - http://mastercode.online
======================================
Python Endswith String Method
In this Python tutorial, we look at how to use the Python endswith string method. This method gives us the ability to search a string object for our argument and if our given argument exists in the string object we will be returned a boolean of True if our argument is not returned then we are returned a boolean of False. The endswith string method have two optional arguments for the starting index and ending index.
Python Endswith String Method Syntax
'string'.endswith('search', start index, end index)
Search - This is a required argument. This must be a string and this is where we include our search term
Start Index - This is an optional argument. Default is 0
End Index - This is an optional argument. The end of the string is default.
Examples of Python Endswith String Method
#Example 1:
a = 'This is our string'
#Example 2:
a.endswith('g')
True
#example 3:
a.endswith('ing')
True
#example 4:
a.endswith('string')
True
#example 5:
a.endswith('r', 0, 11)
True
#example 6:
a.endswith('s', 0, 7)
True
#example 7:
a.endswith('z')
False
Examples Explained
Example 1:
a = 'This is our string' - We create a string object and give it a variable of 'a' to represent the string object.
Example 2:
a.endswith('g')- We call our string object via the variable and call the endswith string method on the string object. We provide a required argument of 'g' to see if the string object ends in 'g'.
True- We are returned True which means that our argument was found by the endswith string method.
Example 3:
a.endswith('ing') - We call our string object via the variable and then we call the endswith string method on our string object. Our argument of 'ing' will go through the string object to see if our string object ends with 'ing'.
True - We are returned True which means that our argument was found by the endswith string method at the end of our string.
Example 4:
a.endswith('string') - We call our string object via the variable and then we call the endswith string method on our string object. Our argument of 'string' will go through the string object to see if our string object ends with 'string'.
True - We are returned True which means that our argument was found by the endswith string method at the end of our string.
Example 5:
a.endswith('r', 0, 11) - We call our string object via the variable and then call the endswith string method on our string object. Our argument of 'r' will look from the 0 index to the 11 index.
True - We are returned True which means that our argument was found by the endswith string method at the ending point 10 index.
On this page of the site you can watch the video online Python endswith String Method with a duration of hours minute second in good quality, which was uploaded by the user Code master 23 September 2015, share the link with friends and acquaintances, this video has already been watched 7,714 times on youtube and it was liked by 80 viewers. Enjoy your viewing!