import string alphas = string.letters nums = string.digits myinput = raw_input(‘>‘) for x in myinput: if x in alphas + nums: balabala.....
每次循环都会把alphas和nums相加,效率低,正确做法应该提前把二者相加的值付给一个变量,对这个变量进行迭代。正确做法如下。
import string #alphas = string.letters #nums = string.digits alphanums = string.letters + string.digits myinput = raw_input(‘>‘) for x in myinput: if x in alphanums: balabala.....
时间: 2024-10-28 19:12:11