Python has an endwith (tuple) method in the String class. This method takes a tuple of strings you want to find and is called on the string object. You can call this method like this:
string = `core java` print (string.endswith ((` txt`, `xml`, `java`,` orld`)))
There is another way to find out whether the string ends with the specified list of suffixes. You can use re.search from the re (regex) module for this. Regex interprets $ as end of line. We also need to separate the suffixes with grouping and | a character in a regular expression. For example,
import re string = `core java` print (bool (re.search (` (java | xml | py | orld) $ ` , string))) print (bool (re.search (`(jav a | xml | py | orld) $`, `core java`))) print (bool (re.search (` (java | xml | py) $ `,` Hello world`)))
True True False
re.search returns an object, to check if it exists or not, we need to convert it to boolean using bool (). You can read more about Python regular expressions here . P >
Data scientist has been called “the sexiest job of the 21st century,” presumably by someone who has never visited a fire station. Nonetheless, 23/09/2020
Systems programming provides the basis for global calculation. Developing performance-sensitive code requires a programming language that allows programmers to control the use of memory, processor tim...
This book is an indispensable guide focuses on Machine Learning and R Programming, in an instructive and conversational tone which helps them who want to make their career in Big Data Analytics/ Data ...
In the summer of 2008, after three decades of building software in corporate data centers, I walked away from corporate America to take a stab at building a technology company from the ground up based...