Search code examples
pythonstartswith

Python: startswith any alpha character


How can I use the startswith function to match any alpha character [a-zA-Z]. For example I would like to do this:

if line.startswith(ALPHA):
    Do Something

Solution

  • If you want to match non-ASCII letters as well, you can use str.isalpha:

    if line and line[0].isalpha():