Check if a string contains a number

后端 未结 16 1617
無奈伤痛
無奈伤痛 2020-11-22 11:14

Most of the questions I\'ve found are biased on the fact they\'re looking for letters in their numbers, whereas I\'m looking for numbers in what I\'d like to be a numberless

16条回答
  •  时光说笑
    2020-11-22 12:05

    alp_num = [x for x in string.split() if x.isalnum() and re.search(r'\d',x) and 
    re.search(r'[a-z]',x)]
    
    print(alp_num)
    

    This returns all the string that has both alphabets and numbers in it. isalpha() returns the string with all digits or all characters.

提交回复
热议问题