Home > Article > Backend Development > Introduction to Python's judgment of whether a parameter is a legal identifier
This article explains in detail about Python's introduction to determining whether a parameter is a legal identifier
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')
The above is the detailed content of Introduction to Python's judgment of whether a parameter is a legal identifier. For more information, please follow other related articles on the PHP Chinese website!