Python: startswith any alpha character

teggy picture teggy · Mar 7, 2010 · Viewed 54.4k times · Source

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

Answer

dan04 picture dan04 · Mar 7, 2010

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

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