PHP前端开发

关于python判断参数是否是合法标识符介绍

百变鹏仔 3个月前 (02-08) #Python
文章标签 标识符

这篇文章详解关于python判断参数是否是合法标识符介绍

import stringdef is_valid_identifier(param):    alphas = string.letters + '_'    nums = string.digits    if len(param) > 1:        if param[0] not in alphas:            print 'invalid:first symbol must be alphabetic'        else:            for otherChar in param[1:]:                if otherChar not in alphas + nums:                    print 'invalid:reminding symbols must be alphanumeric'                    break            else:                 print 'okay, %s is an valid identifier'%paramis_valid_identifier('class')