python列表學習二
阿新 • • 發佈:2018-03-30
學習1.list
#list將字符串輸出成列表
>>> a = ‘abcdefghijklmnopqrstuvwxyz‘
>>> list(a)
[‘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‘]
2.str
#str將列表合成字符串
>>> str(a)
‘abcdefghijklmnopqrstuvwxyz‘
3. ‘‘.join()
#string模塊 >>> import string >>> a = string.lowercase >>> ‘‘.join(a) ‘abcdefghijklmnopqrstuvwxyz‘ #‘‘中可以添加字符串分隔符 >>> ‘|‘.join(a) ‘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‘ >>> a ‘abcdefghijklmnopqrstuvwxyz‘ >>> ‘*‘.join(a) ‘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‘
python列表學習二