In the last article, I shared a simple way that you can use to find the first element in a list without using the index 0.
In case you haven’t read it and you do not want to read it now, here is a short recap that is also going to be helpful in this article.
In summary, you can find the last element in a list using a negative index as you can find any other element in the list. All you have to do is use the negative value of the length of the list:
That’s basically it.
You can use the same technique to also find the first character in a string.
However, for strings, there is an additional way that you can use to check for the value of the first character even without using any index at all. This does not return a character, but a boolean value:
Strings also have a method called endswith which, as you may already guess from its name, can be used to check whether a string ends with a particular character:
That’s pretty much it.
I hope you find this useful.