k668 发表于 2018-8-15 08:21:32

python判断参数是否是合法标识符

  import string
  def is_valid_identifier(param):
  alphas = string.letters + '_'
  nums = string.digits
  if len(param) > 1:
  if param not in alphas:
  print 'invalid:first symbol must be alphabetic'
  else:
  for otherChar in param:
  if otherChar not in alphas + nums:
  print 'invalid:reminding symbols must be alphanumeric'
  break
  else:

  print 'okay, %s is an valid>  is_valid_identifier('class')
  备注:除了关键字和一个长度的
页: [1]
查看完整版本: python判断参数是否是合法标识符