这篇文章详解关于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')
免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。联系邮箱:chuangshanghai#qq.com(把#换成@)