#!usr/bin/env python
# -*- coding:utf-8 -*-
import string #导入Sting模块
alphas = string.letters + '_' #预定义
nums = string.digits
print 'Welcome to the Identifier Checker'
print 'Testees must be at least 2 chars long.'
MyInput = raw_input('Identifier to test:')
if len(MyInput) > 1:
if MyInput[0] not in alphas:
print '''invalid:first symbol must be alphabetic'''
else:
for otherChar in MyInput[1:]:
if otherChar not in alphas + nums:
print '''invalid:remaining symbols must be alphanumeric'''
break
print "OK as an identifier"
标识符检查
标识符检查器
最新推荐文章于 2023-12-05 20:15:29 发布
本文介绍了一个简单的Python程序,用于检查用户输入的标识符是否符合Python的语法规范。程序首先检查首字符是否为字母或下划线,然后验证其余字符是否为字母数字组合。
2174

被折叠的 条评论
为什么被折叠?



