目的:检查字符串是字母数字、数字还是只有字母
代码 :
s2 = "123test"
if s2.isalnum():
print "String is alphanumeric"
elif s2.isalpha():
print "String is alpha"
elif s2.isdigit():
print "String is numeric"
else:
print "No Idea what the string is"
错误:
print "String is alphanumeric"
^
IndentationError: expected an indented block
当我自己做时print s2.isalnum()
,它会打印True
. 我不确定我上面的代码有什么问题。
版本:2.6