list1 = [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]
for item in list1:
print item不确定为什么上面的代码会抛出这个错误:
NameError: "name 'a' is not defined"发布于 2010-01-17 22:08:14
除了正确使用引号外,不要重复输入字母表。
>>> import string
>>> string.ascii_lowercase
'abcdefghijklmnopqrstuvwxyz'
>>> L = list(string.ascii_lowercase)
>>> print L
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', ...
>>> help(string)发布于 2010-01-17 21:59:24
您必须将字符串放在(双)引号中
list1 = ["a","b","c",...] 应该行得通
发布于 2010-01-17 22:01:35
字符串文字应用引号括起来:)
list1 = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]https://stackoverflow.com/questions/2081168
复制相似问题