How can I check if a string contains ANY letters from the alphabet?

前端 未结 7 1671
我在风中等你
我在风中等你 2020-11-29 19:09

What is best pure Python implementation to check if a string contains ANY letters from the alphabet?

string_1 = \"(555).555-5555\"
string_2 = \"(555) 555 - 5         


        
7条回答
  •  温柔的废话
    2020-11-29 19:47

    How about:

    >>> string_1 = "(555).555-5555"
    >>> string_2 = "(555) 555 - 5555 ext. 5555"
    >>> any(c.isalpha() for c in string_1)
    False
    >>> any(c.isalpha() for c in string_2)
    True
    

提交回复
热议问题