str.startswith allows you to supply a tuple of strings to test for:
if link.lower().startswith(("js", "catalog", "script", "katalog")):
From the docs:
str.startswith(prefix[, start[, end]])Return
Trueif string starts with theprefix, otherwise returnFalse.prefixcan also be a tuple of prefixes to look for.
Below is a demonstration:
>>> "abcde".startswith(("xyz", "abc"))
True
>>> prefixes = ["xyz", "abc"]
>>> "abcde".startswith(tuple(prefixes)) # You must use a tuple though
True
>>>
Answer from user2555451 on Stack Overflow Top answer 1 of 3
648
str.startswith allows you to supply a tuple of strings to test for:
if link.lower().startswith(("js", "catalog", "script", "katalog")):
From the docs:
str.startswith(prefix[, start[, end]])Return
Trueif string starts with theprefix, otherwise returnFalse.prefixcan also be a tuple of prefixes to look for.
Below is a demonstration:
>>> "abcde".startswith(("xyz", "abc"))
True
>>> prefixes = ["xyz", "abc"]
>>> "abcde".startswith(tuple(prefixes)) # You must use a tuple though
True
>>>
2 of 3
53
You can also use any(), map() like so:
if any(map(l.startswith, x)):
pass # Do something
Or alternatively, using a generator expression:
if any(l.startswith(s) for s in x)
pass # Do something
YouTube
youtube.com › watch
Python String Startswith – How to Test Multiple Values - YouTube
Full Tutorial: https://blog.finxter.com/python-string-startswith-how-to-test-multiple-values/Email Academy: https://blog.finxter.com/email-academy/►► Do you ...
Published: June 20, 2021
Finxter
blog.finxter.com › home › learn python blog › python string startswith – how to test multiple values
Python String Startswith - How to Test Multiple Values - Be on the Right Side of Change
June 20, 2021 - To check if a given string starts with any of multiple prefixes, convert the iterable of prefixes into a tuple and pass it into the string.startswith() method like so: s.startswith(tuple(prefixes)).
Codecademy
codecademy.com › docs › python › strings › .startswith()
Python | Strings | .startswith() | Codecademy
April 17, 2025 - Since indices 12-24 in string starts with “popular”, the above code produces the following output: ... The following codebyte example uses the Python .startswith() method to determine if the input string starts with any of the strings in the given tuple:
W3Schools
w3schools.com › python › ref_string_startswith.asp
Python String startswith() Method
Remove List Duplicates Reverse ... Python Interview Q&A Python Training ... The startswith() method returns True if the string starts with the specified value, otherwise False....
Programiz
programiz.com › python-programming › methods › string › startswith
Python String startswith()
It's possible to pass a tuple of prefixes to the startswith() method in Python. If the string starts with any item of the tuple, startswith() returns True.
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.str.startswith.html
pandas.Series.str.startswith — pandas 3.0.6 documentation
Equivalent to str.startswith(). ... Character sequence or tuple of strings. Regular expressions are not accepted. ... Object shown if element tested is not a string. The default depends on dtype of the array. For the "str" dtype, False is used. For object dtype, numpy.nan is used. For the nullable StringDtype, pandas.NA is used. ... A Series of booleans indicating whether the given pattern matches the start of each string element. ... Python ...
GeeksforGeeks
geeksforgeeks.org › python-check-if-string-starts-with-any-element-in-list
Python - Check if string starts with any element in list - GeeksforGeeks
January 16, 2025 - We can iterate through the list of substrings and check if the string starts with any of them using the startswith() method. ... s = "geeksforgeeks" prefixes = ["geek", "for", "python"] res = False # Iterating through the list of prefixes for prefix in prefixes: if s.startswith(prefix): # Checking if the string starts with the current prefix res = True break # Exiting the loop as soon as a match is found print(res)
Tutorialspoint
tutorialspoint.com › python › string_startswith.htm
Python String startswith() Method
The Python string method startswith() checks whether string starts with a given substring or not. This method accepts a prefix string that you want to search for and is invoked on a string object.
Xion
xion.io › post › code › python-startswith-tuple.html
Karol Kuczmarski's Blog – str.startswith() with tuple argument
June 28, 2016 - Rather than passing just a single string as the argument, you can provide a tuple of strings instead: SCHEMES = ('http://', 'https://', 'ftp://', 'git://') if s.startswith(SCHEMES): # ...
GeeksforGeeks
geeksforgeeks.org › python › python-string-startswith
Python - String startswith() - GeeksforGeeks
April 29, 2025 - We can also check if the string starts with any one of several prefixes by passing a tuple of prefixes.
Naukri
naukri.com › code360 › library › python-string-startswith
Python String startswith() - Naukri Code 360
August 19, 2025 - Almost there... just a few more seconds
GoLinuxCloud
golinuxcloud.com › home › programming › python › python startswith()
Python startswith(): Check String Prefix, Ignore Case, and Tuple Examples
June 23, 2026 - Pass a tuple to check multiple prefixes. Use start and end when you need to test a specific range. For suffix checks, use endswith() or compare with related string methods such as removeprefix(). ... startswith() returns True if a string begins with the given prefix, otherwise False. It does not change the original string. Yes by default. "Python".startswith("py") returns False because uppercase and lowercase letters are compared exactly.