Python String startswith() Method
Python startswith() method returns either True or False. It returns True if the string starts with the prefix, otherwise False. It takes two parameters start and end. Start is a starting index from where searching starts and end index is where searching stops.
prefix : A string which is to be checked.
start : Start index from where searching starts.
end : End index till there searching performs.
Both start and end are optional parameters.
It returns boolean value either True or False.
Let's see some examples of startswith() method to understand it's functionality.
Python String startswith() Method Example 1
Let's first create a simple example which prints True if the string starts with the prefix.
Python String startswith() Method Example 2
If the string does not start with prefix, the method returns False. See the example below
Python String startswith() Method Example 3
This method takes three parameters. The start and end index are optional. Here, we are passing start index only.
Python String startswith() Method Example 4
It returns true if the string lie between start and end index starts from the prefix. An example is created to describe the process.
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week