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

2025-09-07

这篇文章详解关于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')

标签: python合法的标识符

本文地址:https://www.lifejia.cn/news/209359.html

免责声明:本站内容仅用于学习参考,信息和图片素材来源于互联网,如内容侵权与违规,请联系我们进行删除,我们将在三个工作日内处理。联系邮箱:cloudinto#qq.com(把#换成@)