Python String startswith() MethodPython Functions

Difficulty Level:
Difficulty Level:

The startswith() method is used to check if a string starts with a prefix (the specified string).

Note: the check is case sensitive.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

str = "Have a nice day!"
print(str.startswith('Have'))
print(str.startswith('a', 5))
print(str.startswith('A', 5))

Output:

True
True
False

Syntax

str.startswith(prefix[, start[, end]])

Parameters

Name Description
prefix The string to be checked
start Beginning position where prefix is to be checked within the string
end Ending position where prefix is to be checked within the string

Return Value

It returns true or false.

Advertisement

© 2021 Pythonexample.org, all rights reserved. Privacy Policy | Contact Us