python 不能有return語句嗎?该怎么解决

python 不能有return語句嗎?import stringcheck the identify validenum string.digitsalpha st

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')

第九行,說是return outside function??

[解决办法]

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')