我是靠谱客的博主 默默纸飞机,这篇文章主要介绍python判断参数是否是合法标识符,现在分享给大家,希望可以做个参考。

import string


def 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'%param



is_valid_identifier('class')


备注:除了关键字和一个长度的

转载于:https://blog.51cto.com/11565901/1908462

最后

以上就是默默纸飞机最近收集整理的关于python判断参数是否是合法标识符的全部内容,更多相关python判断参数是否是合法标识符内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部