python 不能有return語句嗎?
import string
'''check the identify valide'''
num = string.digits
alpha = string.letters + '_'
identify = raw_input('Input the id to check')
if len(identify) < 1:
print('The len must large than 1')
return
if identify[0] not in alpha:
print('The first char is error')
return
for item in identify[1:]:
if item not in alpha + num:
print('The identify contains invalide char')
return
print('Ok,valide')
import string
'''check the identify valide'''
num = string.digits
alpha = string.letters + '_'
identify = raw_input('Input the id to check')
def check_valid(msg):
if len(identify) < 1:
print('The len must large than 1')
return False
if identify[0] not in alpha:
print('The first char is error')
return False
for item in identify[1:]:
if item not in alpha + num:
print('The identify contains invalide char')
return False
return True
if __name__ == "__main__":
if check_valid(identify):
print('Ok,valide')
else:
print('invalid')