如何检查我的列表中是否包含符号或数字(Python)
我正在用Python制作一个破译代码的游戏,需要写一个判断语句,来检查列表里是否有符号或者数字。
这样它就可以告诉我:
list=[hello, bonjour, 4 , hola]`
包含一个数字。而:
list2=[hello, bonjour, hola]
不包含数字
1 个回答
3
只需要这样做:
>>> test = 'abc123%def'
>>> any(not x.isalpha() for x in test)
True
>>> test2 = 'abc'
>>> any(not x.isalpha() for x in test2)
False