问题描述
假设您的字符串是s
:
'$' in s # found '$' not in s # not found # original answer given, but less Pythonic than the above... s.find('$')==-1 # not found s.find('$')!=-1 # found
@H_502_7@对于其他字符,依此类推。
… 要么
pattern = re.compile(r'\d\$,') if pattern.findall(s): print('Found') else print('Not found')
@H_502_7@… 要么
chars = set('0123456789$,') if any((c in chars) for c in s): print('Found') else: print('Not Found')
@H_502_7@[编辑:添加
'$' in s
答案]解决方法
如何使用Python 2检查字符串中是否包含几个特定字符?
例如,给定以下字符串:
罪犯偷走了1,000,000美元的珠宝。
如何检测它是否带有美元符号(“ $”),逗号(“,”)和数字?