您可以使用以下简单if
条件any
:
s='fdsfgsgsfds9'
if len(s)==7 and not any(c.isspace() for c in s) and s[-1].isdigit():
pass
Run Code Online (Sandbox Code Playgroud)
它可能比它的价值更复杂,但您可以使用正则表达式检查所有这些条件.
例如,如果您想要的大小为8个字符,则可以使用以下方法检查所有三个条件:
if re.match(r'\S{7}\d$', text):
print 'all conditions match'
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
150 次 |
最近记录: |