这篇文章详解关于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')以上就是关于python判断参数是否是合法标识符介绍的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号