startswith or python code example
Example 1: python startswith
text = "Python is easy to learn."
result = text.startswith('is easy')
# returns False
print(result)
result = text.startswith('Python is ')
# returns True
print(result)
result = text.startswith('Python is easy to learn.')
# returns True
print(result)
Example 2: string startswith python
# str -> the prefix you are looking for
# beg -> where to start looking for the prefix
# end -> where to stop looking for the prefix
str.startswith(str, beg=0,end=len(string))
Example 3: python string starts with any char of list
# `str.startswith` supports checking for multiple prefixes:
>>> "abcde".startswith(("xyz", "abc"))
True
# You must use a tuple though, so convert your lists using tuple()
>>> prefixes = ["xyz", "abc"]
>>> "abcde".startswith(tuple(prefixes))
True